Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "c.h"
00028
00029 #include <ctype.h>
00030
00031
00032
00033
00034
00035 int
00036 pg_strcasecmp(const char *s1, const char *s2)
00037 {
00038 for (;;)
00039 {
00040 unsigned char ch1 = (unsigned char) *s1++;
00041 unsigned char ch2 = (unsigned char) *s2++;
00042
00043 if (ch1 != ch2)
00044 {
00045 if (ch1 >= 'A' && ch1 <= 'Z')
00046 ch1 += 'a' - 'A';
00047 else if (IS_HIGHBIT_SET(ch1) && isupper(ch1))
00048 ch1 = tolower(ch1);
00049
00050 if (ch2 >= 'A' && ch2 <= 'Z')
00051 ch2 += 'a' - 'A';
00052 else if (IS_HIGHBIT_SET(ch2) && isupper(ch2))
00053 ch2 = tolower(ch2);
00054
00055 if (ch1 != ch2)
00056 return (int) ch1 - (int) ch2;
00057 }
00058 if (ch1 == 0)
00059 break;
00060 }
00061 return 0;
00062 }
00063
00064
00065
00066
00067
00068 int
00069 pg_strncasecmp(const char *s1, const char *s2, size_t n)
00070 {
00071 while (n-- > 0)
00072 {
00073 unsigned char ch1 = (unsigned char) *s1++;
00074 unsigned char ch2 = (unsigned char) *s2++;
00075
00076 if (ch1 != ch2)
00077 {
00078 if (ch1 >= 'A' && ch1 <= 'Z')
00079 ch1 += 'a' - 'A';
00080 else if (IS_HIGHBIT_SET(ch1) && isupper(ch1))
00081 ch1 = tolower(ch1);
00082
00083 if (ch2 >= 'A' && ch2 <= 'Z')
00084 ch2 += 'a' - 'A';
00085 else if (IS_HIGHBIT_SET(ch2) && isupper(ch2))
00086 ch2 = tolower(ch2);
00087
00088 if (ch1 != ch2)
00089 return (int) ch1 - (int) ch2;
00090 }
00091 if (ch1 == 0)
00092 break;
00093 }
00094 return 0;
00095 }
00096
00097
00098
00099
00100
00101
00102
00103
00104 unsigned char
00105 pg_toupper(unsigned char ch)
00106 {
00107 if (ch >= 'a' && ch <= 'z')
00108 ch += 'A' - 'a';
00109 else if (IS_HIGHBIT_SET(ch) && islower(ch))
00110 ch = toupper(ch);
00111 return ch;
00112 }
00113
00114
00115
00116
00117
00118
00119
00120
00121 unsigned char
00122 pg_tolower(unsigned char ch)
00123 {
00124 if (ch >= 'A' && ch <= 'Z')
00125 ch += 'a' - 'A';
00126 else if (IS_HIGHBIT_SET(ch) && isupper(ch))
00127 ch = tolower(ch);
00128 return ch;
00129 }
00130
00131
00132
00133
00134 unsigned char
00135 pg_ascii_toupper(unsigned char ch)
00136 {
00137 if (ch >= 'a' && ch <= 'z')
00138 ch += 'A' - 'a';
00139 return ch;
00140 }
00141
00142
00143
00144
00145 unsigned char
00146 pg_ascii_tolower(unsigned char ch)
00147 {
00148 if (ch >= 'A' && ch <= 'Z')
00149 ch += 'a' - 'A';
00150 return ch;
00151 }