Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

xmlchar.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002     xmlchar.cpp  -  Definitions of some XmlChar specific functions.
00003                              -------------------
00004     begin                : October 10 2002
00005     copyright            : (C) 2003 by Vojtìch Toman
00006     email                : vtoman@lit.cz
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00026 #include "xmlchar.h"
00027 
00028 
00029 
00030 size_t xmlchar_strlen(const XmlChar *str)
00031 {
00032   size_t i;
00033 
00034   if (!str)
00035     return 0;
00036 
00037   for (i = 0; str[i]; i++);
00038 
00039   return i;
00040 }
00041 
00042 
00043 
00044 
00045 
00046 XmlChar *xmlchar_strcpy(XmlChar *dest, const XmlChar *src)
00047 {
00048   size_t i;
00049 
00050   for (i = 0; src[i]; i++)
00051     {
00052       dest[i] = src[i];
00053     }
00054 
00055   dest[i] = 0;
00056 
00057   return dest;
00058 }
00059 
00060 XmlChar *xmlchar_cstrcpy(XmlChar *dest, const char *src)
00061 {
00062   size_t i;
00063 
00064   for (i = 0; src[i]; i++)
00065     {
00066       dest[i] = (XmlChar)src[i];
00067     }
00068 
00069   dest[i] = 0;
00070 
00071   return dest;
00072 }
00073 
00074 
00075 
00076 XmlChar *xmlchar_strncpy(XmlChar *dest, const XmlChar *src, size_t n)
00077 {
00078   size_t i;
00079 
00080   for (i = 0; src[i] && i < n; i++)
00081     {
00082       dest[i] = src[i];
00083     }
00084 
00085   if (i < n)
00086     dest[i] = 0;
00087 
00088 
00089   return dest;
00090 
00091 }
00092 
00093 
00094 
00095 XmlChar *xmlchar_cstrncpy(XmlChar *dest, const char *src, size_t n)
00096 {
00097   size_t i;
00098 
00099   for (i = 0; src[i] && i < n; i++)
00100     {
00101       dest[i] = (XmlChar)src[i];
00102     }
00103 
00104   if (i < n)
00105     dest[i] = 0;
00106 
00107 
00108   return dest;
00109 
00110 }
00111 
00112 
00113 
00114 XmlChar *xmlchar_strcat(XmlChar *dest, const XmlChar *src)
00115 {
00116   size_t i, j;
00117 
00118   for (j = 0; dest[j]; j++);
00119 
00120   for (i = 0; src[i]; i++)
00121     {
00122       dest[j+i] = src[i];
00123     }
00124 
00125   dest[j+i] = 0;
00126 
00127   return dest;
00128 }
00129 
00130 
00131 XmlChar *xmlchar_cstrcat(XmlChar *dest, const char *src)
00132 {
00133   size_t i, j;
00134 
00135   for (j = 0; dest[j]; j++);
00136 
00137   for (i = 0; src[i]; i++)
00138     {
00139       dest[j+i] = (XmlChar)src[i];
00140     }
00141 
00142   dest[j+i] = 0;
00143 
00144   return dest;
00145 }
00146 
00147 
00148 XmlChar *xmlchar_strncat(XmlChar *dest, const XmlChar *src, size_t n)
00149 {
00150   size_t i, j;
00151 
00152   for (j = 0; dest[j]; j++);
00153 
00154   for (i = 0; src[i] && i < n; i++)
00155     {
00156       dest[j+i] = src[i];
00157     }
00158 
00159   if (i < n)
00160     dest[j+i] = 0;
00161 
00162   return dest;
00163 }
00164 
00165 
00166 XmlChar *xmlchar_cstrncat(XmlChar *dest, const char *src, size_t n)
00167 {
00168   size_t i, j;
00169 
00170   for (j = 0; dest[j]; j++);
00171 
00172   for (i = 0; src[i] && i < n; i++)
00173     {
00174       dest[j+i] = (XmlChar)src[i];
00175     }
00176 
00177   if (i < n)
00178     dest[j+i] = 0;
00179 
00180   return dest;
00181 }
00182 
00183 
00184 
00185 int xmlchar_strcmp(const XmlChar *s1, const XmlChar *s2)
00186 {
00187   size_t i;
00188 
00189   i = 0;
00190 
00191   if (!s1 && s2)
00192     //s1 is null
00193     return -1;
00194   else
00195     if (s1 && !s2)
00196       //s2 is null
00197       return 1;
00198     else
00199       if (!s1 && !s2)
00200         //both null
00201         return 0;
00202 
00203 
00204   while (s1[i] && s2[i])
00205     {
00206       if (s1[i] == s2[i])
00207         //characters are equal
00208         i++;
00209       else
00210         if (s1[i] < s2[i])
00211           //s1 is smaller
00212           return -1;
00213         else
00214           //s1 is greater
00215           return 1;
00216     }
00217 
00218   if (s1[i])
00219     //s1 is longer
00220     return 1;
00221   else
00222     if (s2[i])
00223       //s1 is shorter
00224       return -1;
00225     else
00226       //s1 and s2 are equal
00227       return 0;
00228 }
00229 
00230 
00231 int xmlchar_strncmp(const XmlChar *s1, const XmlChar *s2, size_t n)
00232 {
00233   size_t i;
00234 
00235   i = 0;
00236 
00237   if (!s1 && s2)
00238     //s1 is null
00239     return -1;
00240   else
00241     if (s1 && !s2)
00242       //s2 is null
00243       return 1;
00244     else
00245       if (!s1 && !s2)
00246         //both null
00247         return 0;
00248 
00249   while (s1[i] && s2[i] && i < n)
00250     {
00251       if (s1[i] == s2[i])
00252         //characters are equal
00253         i++;
00254       else
00255         if (s1[i] < s2[i])
00256           //s1 is smaller
00257           return -1;
00258         else
00259           //s1 is greater
00260           return 1;
00261     }
00262 
00263   if (s1[i] && s2[i])
00264     //equal (n reached)
00265     return 0;
00266   else
00267     if (!s1[i] && !s2[i])
00268       //equal
00269       return 0;
00270 
00271   if (s2[i])
00272     //s1 is shorter
00273     return -1;
00274   else
00275     //s1 is larger
00276     return 1;
00277 }
00278 
00279 
00280 int xmlchar_cstrcmp(const XmlChar *s1, const char *s2)
00281 {
00282   size_t i;
00283 
00284   i = 0;
00285 
00286   if (!s1 && s2)
00287     //s1 is null
00288     return -1;
00289   else
00290     if (s1 && !s2)
00291       //s2 is null
00292       return 1;
00293     else
00294       if (!s1 && !s2)
00295         //both null
00296         return 0;
00297 
00298 
00299   while (s1[i] && s2[i])
00300     {
00301       if (s1[i] == s2[i])
00302         //characters are equal
00303         i++;
00304       else
00305         if (s1[i] < s2[i])
00306           //s1 is smaller
00307           return -1;
00308         else
00309           //s1 is greater
00310           return 1;
00311     }
00312 
00313   if (s1[i])
00314     //s1 is longer
00315     return 1;
00316   else
00317     if (s2[i])
00318       //s1 is shorter
00319       return -1;
00320     else
00321       //s1 and s2 are equal
00322       return 0;
00323 }
00324 
00325 
00326 int xmlchar_cstrncmp(const XmlChar *s1, const char *s2, size_t n)
00327 {
00328   size_t i;
00329 
00330   i = 0;
00331 
00332   if (!s1 && s2)
00333     //s1 is null
00334     return -1;
00335   else
00336     if (s1 && !s2)
00337       //s2 is null
00338       return 1;
00339     else
00340       if (!s1 && !s2)
00341         //both null
00342         return 0;
00343 
00344   while (s1[i] && s2[i] && i < n)
00345     {
00346       if (s1[i] == s2[i])
00347         //characters are equal
00348         i++;
00349       else
00350         if (s1[i] < s2[i])
00351           //s1 is smaller
00352           return -1;
00353         else
00354           //s1 is greater
00355           return 1;
00356     }
00357 
00358   if (s1[i] && s2[i])
00359     //equal (n reached)
00360     return 0;
00361   else
00362     if (!s1[i] && !s2[i])
00363       //equal
00364       return 0;
00365 
00366   if (s2[i])
00367     //s1 is shorter
00368     return -1;
00369   else
00370     //s1 is larger
00371     return 1;
00372 }

Generated on Wed Feb 5 10:43:02 2003 for Exalt by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002