• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

ParseRules.h

Go to the documentation of this file.
00001 /** @file
00002 
00003   A brief file description
00004 
00005   @section license License
00006 
00007   Licensed to the Apache Software Foundation (ASF) under one
00008   or more contributor license agreements.  See the NOTICE file
00009   distributed with this work for additional information
00010   regarding copyright ownership.  The ASF licenses this file
00011   to you under the Apache License, Version 2.0 (the
00012   "License"); you may not use this file except in compliance
00013   with the License.  You may obtain a copy of the License at
00014 
00015       http://www.apache.org/licenses/LICENSE-2.0
00016 
00017   Unless required by applicable law or agreed to in writing, software
00018   distributed under the License is distributed on an "AS IS" BASIS,
00019   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00020   See the License for the specific language governing permissions and
00021   limitations under the License.
00022  */
00023 
00024 #if !defined (_ParseRules_h_)
00025 #define _ParseRules_h_
00026 
00027 #include <string.h>
00028 
00029 #include "ink_defs.h"
00030 #include "ink_apidefs.h"
00031 #include "ink_platform.h"
00032 
00033 typedef unsigned int CTypeResult;
00034 
00035 // Set this to 0 to disable SI
00036 // decimal multipliers
00037 #define USE_SI_MULTILIERS    1
00038 
00039 #define is_char_BIT         (1 << 0)
00040 #define is_upalpha_BIT      (1 << 1)
00041 #define is_loalpha_BIT      (1 << 2)
00042 #define is_alpha_BIT        (1 << 3)
00043 #define is_digit_BIT        (1 << 4)
00044 #define is_ctl_BIT          (1 << 5)
00045 #define is_ws_BIT           (1 << 6)
00046 #define is_hex_BIT          (1 << 7)
00047 #define is_pchar_BIT        (1 << 8)
00048 #define is_extra_BIT        (1 << 9)
00049 #define is_safe_BIT         (1 << 10)
00050 #define is_unsafe_BIT       (1 << 11)
00051 #define is_national_BIT     (1 << 12)
00052 #define is_reserved_BIT     (1 << 13)
00053 #define is_unreserved_BIT   (1 << 14)
00054 #define is_punct_BIT        (1 << 15)
00055 #define is_end_of_url_BIT   (1 << 16)
00056 #define is_tspecials_BIT    (1 << 17)
00057 #define is_spcr_BIT         (1 << 18)
00058 #define is_splf_BIT         (1 << 19)
00059 #define is_wslfcr_BIT       (1 << 20)
00060 #define is_eow_BIT          (1 << 21)
00061 #define is_token_BIT        (1 << 22)
00062 #define is_wildmat_BIT      (1 << 23)
00063 #define is_sep_BIT          (1 << 24)
00064 #define is_empty_BIT        (1 << 25)
00065 #define is_alnum_BIT        (1 << 26)
00066 #define is_space_BIT        (1 << 27)
00067 #define is_control_BIT      (1 << 28)
00068 #define is_mime_sep_BIT     (1 << 29)
00069 #define is_http_field_name_BIT  (1 << 30)
00070 /* shut up the DEC compiler */
00071 #define is_http_field_value_BIT (((CTypeResult)1) << 31)
00072 
00073 extern ink_undoc_liapi const CTypeResult parseRulesCType[];
00074 inkcoreapi extern const char parseRulesCTypeToUpper[];
00075 inkcoreapi extern const char parseRulesCTypeToLower[];
00076 
00077 class ParseRules
00078 {
00079 public:
00080   ParseRules();
00081 
00082   ////////////////////////////
00083   // whitespace definitions //
00084   ////////////////////////////
00085 
00086   enum
00087   {
00088     CHAR_SP = 32,               /* space           */
00089     CHAR_HT = 9,                /* horizontal tab  */
00090     CHAR_LF = 10,               /* line feed       */
00091     CHAR_VT = 11,               /* vertical tab    */
00092     CHAR_NP = 12,               /* new page        */
00093     CHAR_CR = 13                /* carriage return */
00094   };
00095 
00096   /////////////////////
00097   // character tests //
00098   /////////////////////
00099 
00100   static CTypeResult is_type(char c, uint32_t bit);
00101 
00102   static CTypeResult is_char(char c);   // ASCII 0-127
00103   static CTypeResult is_upalpha(char c);        // A-Z
00104   static CTypeResult is_loalpha(char c);        // a-z
00105   static CTypeResult is_alpha(char c);  // A-Z,a-z
00106   static CTypeResult is_digit(char c);  // 0-9
00107   static CTypeResult is_ctl(char c);    // ASCII 0-31,127 (includes ws)
00108   static CTypeResult is_hex(char c);    // 0-9,A-F,a-f
00109   static CTypeResult is_ws(char c);     // SP,HT
00110   static CTypeResult is_cr(char c);     // CR
00111   static CTypeResult is_lf(char c);     // LF
00112   static CTypeResult is_spcr(char c);   // SP,CR
00113   static CTypeResult is_splf(char c);   // SP,LF
00114   static CTypeResult is_wslfcr(char c); // SP,HT,LF,CR
00115   static CTypeResult is_tspecials(char c);      // HTTP chars that need quoting
00116   static CTypeResult is_token(char c);  // token (not CTL or specials)
00117   static CTypeResult is_extra(char c);  // !,*,QUOT,(,),COMMA
00118   static CTypeResult is_safe(char c);   // [$-_.+]
00119   static CTypeResult is_unsafe(char c); // SP,DBLQUOT,#,%,<,>
00120   static CTypeResult is_national(char c);       // {,},|,BACKSLASH,^,~,[,],`
00121   static CTypeResult is_reserved(char c);       // :,/,?,:,@,&,=
00122   static CTypeResult is_unreserved(char c);     // alpha,digit,safe,extra,nat.
00123   static CTypeResult is_punct(char c);  // !"#$%&'()*+,-./:;<>=?@_{}|~
00124   static CTypeResult is_end_of_url(char c);     // NUL,CR,SP
00125   static CTypeResult is_eow(char c);    // NUL,CR,LF
00126   static CTypeResult is_wildmat(char c);        // \,*,?,[
00127   static CTypeResult is_sep(char c);    // NULL,COMMA,':','!',wslfcr
00128   static CTypeResult is_empty(char c);  // wslfcr,#
00129   static CTypeResult is_alnum(char c);  // 0-9,A-Z,a-z
00130   static CTypeResult is_space(char c);  // ' ' HT,VT,NP,CR,LF
00131   static CTypeResult is_control(char c);        // 0-31 127
00132   static CTypeResult is_mime_sep(char c);       // ()<>,;\"/[]?{} \t
00133   static CTypeResult is_http_field_name(char c);        // not : or mime_sep except for @
00134   static CTypeResult is_http_field_value(char c);       // not CR, LF, comma, or "
00135 
00136   //////////////////
00137   // string tests //
00138   //////////////////
00139 
00140   static CTypeResult is_escape(const char *seq);        // %<hex><hex>
00141   static CTypeResult is_uchar(const char *seq); // starts unresrvd or is escape
00142   static CTypeResult is_pchar(const char *seq); // uchar,:,@,&,=,+ (see code)
00143 
00144   ///////////////////
00145   // unimplemented //
00146   ///////////////////
00147 
00148   //static CTypeResult   is_comment(const char * str);
00149   //static CTypeResult   is_ctext(const char * str);
00150 
00151   ////////////////
00152   // operations //
00153   ////////////////
00154 
00155   static CTypeResult strncasecmp_eow(const char *s1, const char *s2, int n);
00156   static const char *strcasestr(const char *s1, const char *s2);
00157   static int strlen_eow(const char *s);
00158   static const char *strstr_eow(const char *s1, const char *s2);
00159 
00160   static char ink_toupper(char c);
00161   static char ink_tolower(char c);
00162   static void ink_tolower_buffer(char *ptr, unsigned int n);
00163   static const char *memchr(const char *s, char c, int max_length);
00164   static const char *strchr(const char *s, char c);
00165 
00166   static unsigned char *scan_while(unsigned char *ptr, unsigned int n, uint32_t bitmask);
00167 
00168 private:
00169     ParseRules(const ParseRules &);
00170     ParseRules & operator =(const ParseRules &);
00171 };
00172 
00173 /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
00174  * inline functions definitions
00175  * * * * * * * * * * * * * * * * * * * * * * * * * * * */
00176 
00177 inline CTypeResult
00178 ParseRules::is_type(char c, uint32_t bitmask)
00179 {
00180   return (parseRulesCType[(unsigned char) c] & bitmask);
00181 }
00182 
00183 inline CTypeResult
00184 ParseRules::is_char(char c)
00185 {
00186 #ifndef COMPILE_PARSE_RULES
00187   return (parseRulesCType[(unsigned char) c] & is_char_BIT);
00188 #else
00189   return ((c & 0x80) == 0);
00190 #endif
00191 }
00192 
00193 inline CTypeResult
00194 ParseRules::is_upalpha(char c)
00195 {
00196 #ifndef COMPILE_PARSE_RULES
00197   return (parseRulesCType[(unsigned char) c] & is_upalpha_BIT);
00198 #else
00199   return (c >= 'A' && c <= 'Z');
00200 #endif
00201 }
00202 
00203 inline CTypeResult
00204 ParseRules::is_loalpha(char c)
00205 {
00206 #ifndef COMPILE_PARSE_RULES
00207   return (parseRulesCType[(unsigned char) c] & is_loalpha_BIT);
00208 #else
00209   return (c >= 'a' && c <= 'z');
00210 #endif
00211 }
00212 
00213 inline CTypeResult
00214 ParseRules::is_alpha(char c)
00215 {
00216 #ifndef COMPILE_PARSE_RULES
00217   return (parseRulesCType[(unsigned char) c] & is_alpha_BIT);
00218 #else
00219   return (is_upalpha(c) || is_loalpha(c));
00220 #endif
00221 }
00222 
00223 inline CTypeResult
00224 ParseRules::is_digit(char c)
00225 {
00226 #ifndef COMPILE_PARSE_RULES
00227   return (parseRulesCType[(unsigned char) c] & is_digit_BIT);
00228 #else
00229   return (c >= '0' && c <= '9');
00230 #endif
00231 }
00232 
00233 inline CTypeResult
00234 ParseRules::is_alnum(char c)
00235 {
00236 #ifndef COMPILE_PARSE_RULES
00237   return (parseRulesCType[(unsigned char) c] & is_alnum_BIT);
00238 #else
00239   return (is_alpha(c) || is_digit(c));
00240 #endif
00241 }
00242 
00243 inline CTypeResult
00244 ParseRules::is_ctl(char c)
00245 {
00246 #ifndef COMPILE_PARSE_RULES
00247   return (parseRulesCType[(unsigned char) c] & is_ctl_BIT);
00248 #else
00249   return ((!(c & 0x80) && c <= 31) || c == 127);
00250 #endif
00251 }
00252 
00253 inline CTypeResult
00254 ParseRules::is_ws(char c)
00255 {
00256 #ifndef COMPILE_PARSE_RULES
00257   return (parseRulesCType[(unsigned char) c] & is_ws_BIT);
00258 #else
00259   return (c == CHAR_SP || c == CHAR_HT);
00260 #endif
00261 }
00262 
00263 inline CTypeResult
00264 ParseRules::is_hex(char c)
00265 {
00266 #ifndef COMPILE_PARSE_RULES
00267   return (parseRulesCType[(unsigned char) c] & is_hex_BIT);
00268 #else
00269   return ((c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f') || (c >= '0' && c <= '9'));
00270 #endif
00271 }
00272 
00273 inline CTypeResult
00274 ParseRules::is_cr(char c)
00275 {
00276   return (c == CHAR_CR);
00277 }
00278 
00279 inline CTypeResult
00280 ParseRules::is_lf(char c)
00281 {
00282   return (c == CHAR_LF);
00283 }
00284 
00285 inline CTypeResult
00286 ParseRules::is_splf(char c)
00287 {
00288 #ifndef COMPILE_PARSE_RULES
00289   return (parseRulesCType[(unsigned char) c] & is_splf_BIT);
00290 #else
00291   return (c == CHAR_SP || c == CHAR_LF);
00292 #endif
00293 }
00294 
00295 inline CTypeResult
00296 ParseRules::is_spcr(char c)
00297 {
00298 #ifndef COMPILE_PARSE_RULES
00299   return (parseRulesCType[(unsigned char) c] & is_spcr_BIT);
00300 #else
00301   return (c == CHAR_SP || c == CHAR_CR);
00302 #endif
00303 }
00304 
00305 inline CTypeResult
00306 ParseRules::is_wslfcr(char c)
00307 {
00308 #ifndef COMPILE_PARSE_RULES
00309   return (parseRulesCType[(unsigned char) c] & is_wslfcr_BIT);
00310 #else
00311   return ParseRules::is_ws(c) || ParseRules::is_splf(c) || ParseRules::is_spcr(c);
00312 #endif
00313 }
00314 
00315 inline CTypeResult
00316 ParseRules::is_extra(char c)
00317 {
00318 #ifndef COMPILE_PARSE_RULES
00319   return (parseRulesCType[(unsigned char) c] & is_extra_BIT);
00320 #else
00321   switch (c) {
00322   case '!':
00323   case '*':
00324   case '\'':
00325   case '(':
00326   case ')':
00327   case ',':
00328     return (true);
00329   }
00330   return (false);
00331 #endif
00332 }
00333 
00334 inline CTypeResult
00335 ParseRules::is_safe(char c)
00336 {
00337 #ifndef COMPILE_PARSE_RULES
00338   return (parseRulesCType[(unsigned char) c] & is_safe_BIT);
00339 #else
00340   return (c == '$' || c == '-' || c == '_' || c == '.' || c == '+');
00341 #endif
00342 }
00343 
00344 inline CTypeResult
00345 ParseRules::is_unsafe(char c)
00346 {
00347 #ifndef COMPILE_PARSE_RULES
00348   return (parseRulesCType[(unsigned char) c] & is_unsafe_BIT);
00349 #else
00350   if (is_ctl(c))
00351     return (true);
00352 
00353   switch (c) {
00354   case ' ':
00355   case '\"':
00356   case '#':
00357   case '%':
00358   case '<':
00359   case '>':
00360     return (true);
00361   }
00362   return (false);
00363 #endif
00364 }
00365 
00366 inline CTypeResult
00367 ParseRules::is_reserved(char c)
00368 {
00369 #ifndef COMPILE_PARSE_RULES
00370   return (parseRulesCType[(unsigned char) c] & is_reserved_BIT);
00371 #else
00372   switch (c) {
00373   case ';':
00374   case '/':
00375   case '?':
00376   case ':':
00377   case '@':
00378   case '&':
00379   case '=':
00380     return (true);
00381   }
00382   return (false);
00383 #endif
00384 }
00385 
00386 inline CTypeResult
00387 ParseRules::is_national(char c)
00388 {
00389 #ifndef COMPILE_PARSE_RULES
00390   return (parseRulesCType[(unsigned char) c] & is_national_BIT);
00391 #else
00392   switch (c) {
00393   case '{':
00394   case '}':
00395   case '|':
00396   case '\\':
00397   case '^':
00398   case '~':
00399   case '[':
00400   case ']':
00401   case '`':
00402     return (true);
00403   }
00404   return (false);
00405 #endif
00406 }
00407 
00408 inline CTypeResult
00409 ParseRules::is_unreserved(char c)
00410 {
00411 #ifndef COMPILE_PARSE_RULES
00412   return (parseRulesCType[(unsigned char) c] & is_unreserved_BIT);
00413 #else
00414   return (is_alpha(c) || is_digit(c) || is_safe(c) || is_extra(c) || is_national(c));
00415 #endif
00416 }
00417 
00418 inline CTypeResult
00419 ParseRules::is_punct(char c)
00420 {
00421 #ifndef COMPILE_PARSE_RULES
00422   return (parseRulesCType[(unsigned char) c] & is_punct_BIT);
00423 #else
00424   switch (c) {
00425   case '!':
00426   case '"':
00427   case '#':
00428   case '%':
00429   case '&':
00430   case '\'':
00431   case '(':
00432   case ')':
00433   case '*':
00434   case '+':
00435   case ',':
00436   case '-':
00437   case '.':
00438   case '/':
00439   case ':':
00440   case ';':
00441   case '<':
00442   case '=':
00443   case '>':
00444   case '?':
00445   case '@':
00446   case '[':
00447   case '\\':
00448   case ']':
00449   case '^':
00450   case '_':
00451   case '`':
00452   case '{':
00453   case '|':
00454   case '}':
00455   case '~':
00456     return (true);
00457   }
00458   return (false);
00459 #endif
00460 }
00461 
00462 inline CTypeResult
00463 ParseRules::is_end_of_url(char c)
00464 {
00465 #ifndef COMPILE_PARSE_RULES
00466   return (parseRulesCType[(unsigned char) c] & is_end_of_url_BIT);
00467 #else
00468   return (c == '\0' || c == '\n' || c == ' ' || ParseRules::is_ctl(c)
00469     );
00470 #endif
00471 }
00472 
00473 inline CTypeResult
00474 ParseRules::is_escape(const char *seq)
00475 {
00476   return (seq[0] == '%' && is_hex(seq[1]) && is_hex(seq[2]));
00477 }
00478 
00479 inline CTypeResult
00480 ParseRules::is_uchar(const char *seq)
00481 {
00482   return (is_unreserved(seq[0]) || is_escape(seq));
00483 }
00484 
00485 //
00486 // have to cheat on this one
00487 //
00488 inline CTypeResult
00489 ParseRules::is_pchar(const char *seq)
00490 {
00491 #ifndef COMPILE_PARSE_RULES
00492   if (*seq != '%')
00493     return (parseRulesCType[(uint8_t)*seq] & is_pchar_BIT);
00494   else
00495     return is_hex(seq[1]) && is_hex(seq[2]);
00496 #else
00497   if (is_unreserved(*seq))
00498     return (true);
00499 
00500   switch (seq[0]) {
00501   case ':':
00502   case '@':
00503   case '&':
00504   case '=':
00505   case '+':
00506     return (true);
00507   }
00508   return (false);
00509 #endif
00510 }
00511 
00512 inline CTypeResult
00513 ParseRules::is_tspecials(char c)
00514 {
00515 #ifndef COMPILE_PARSE_RULES
00516   return (parseRulesCType[(unsigned char) c] & is_tspecials_BIT);
00517 #else
00518   switch (c) {
00519   case '(':
00520   case ')':
00521   case '<':
00522   case '>':
00523   case '@':
00524   case ',':
00525   case ';':
00526   case ':':
00527   case '\\':
00528   case '"':
00529   case '/':
00530   case '[':
00531   case ']':
00532   case '?':
00533   case '=':
00534   case '{':
00535   case '}':
00536   case CHAR_SP:
00537   case CHAR_HT:
00538     return (true);
00539   }
00540   return (false);
00541 #endif
00542 }
00543 
00544 inline CTypeResult
00545 ParseRules::is_token(char c)
00546 {
00547 #ifndef COMPILE_PARSE_RULES
00548   return (parseRulesCType[(unsigned char) c] & is_token_BIT);
00549 #else
00550   return (is_char(c) && !(is_ctl(c) || is_tspecials(c)));
00551 #endif
00552 }
00553 
00554 inline char
00555 ParseRules::ink_toupper(char c)
00556 {
00557 #ifndef COMPILE_PARSE_RULES
00558   return parseRulesCTypeToUpper[(unsigned char) c];
00559 #else
00560   int up_case = c;
00561   const int up_case_diff = 'a' - 'A';
00562 
00563   if (c >= 'a' && c <= 'z') {
00564     up_case = c - up_case_diff;
00565   }
00566   return (up_case);
00567 #endif
00568 }
00569 
00570 inline char
00571 ParseRules::ink_tolower(char c)
00572 {
00573 #ifndef COMPILE_PARSE_RULES
00574   return parseRulesCTypeToLower[(unsigned char) c];
00575 #else
00576   int lo_case = c;
00577   const int lo_case_diff = 'a' - 'A';
00578 
00579   if (c >= 'A' && c <= 'Z') {
00580     lo_case = c + lo_case_diff;
00581   }
00582   return (lo_case);
00583 #endif
00584 }
00585 
00586 inline CTypeResult
00587 ParseRules::is_eow(char c)
00588 {
00589 #ifndef COMPILE_PARSE_RULES
00590   return (parseRulesCType[(unsigned char) c] & is_eow_BIT);
00591 #else
00592   return (c == '\0' || c == '\r' || c == '\n');
00593 #endif
00594 }
00595 
00596 inline CTypeResult
00597 ParseRules::is_wildmat(char c)
00598 {
00599 #ifndef COMPILE_PARSE_RULES
00600   return (parseRulesCType[(unsigned char) c] & is_wildmat_BIT);
00601 #else
00602   return (c == '*' || c == '?' || c == '[' || c == '\\');
00603 #endif
00604 }
00605 
00606 inline CTypeResult
00607 ParseRules::is_sep(char c)
00608 {
00609 #ifndef COMPILE_PARSE_RULES
00610   return (parseRulesCType[(unsigned char) c] & is_sep_BIT);
00611 #else
00612   return (!c || c == ',' || c == ':' || c == '!' || is_wslfcr(c));
00613 #endif
00614 }
00615 
00616 inline CTypeResult
00617 ParseRules::is_empty(char c)
00618 {
00619 #ifndef COMPILE_PARSE_RULES
00620   return (parseRulesCType[(unsigned char) c] & is_empty_BIT);
00621 #else
00622   return (c == '#' || is_wslfcr(c));
00623 #endif
00624 }
00625 
00626 inline CTypeResult
00627 ParseRules::is_space(char c)
00628 {
00629 #ifndef COMPILE_PARSE_RULES
00630   return (parseRulesCType[(unsigned char) c] & is_space_BIT);
00631 #else
00632   switch (c) {
00633   case CHAR_SP:
00634   case CHAR_HT:
00635   case CHAR_LF:
00636   case CHAR_VT:
00637   case CHAR_NP:
00638   case CHAR_CR:
00639     return (true);
00640   }
00641   return (false);
00642 #endif
00643 }
00644 
00645 inline CTypeResult
00646 ParseRules::is_control(char c)
00647 {
00648 #ifndef COMPILE_PARSE_RULES
00649   return (parseRulesCType[(unsigned char) c] & is_control_BIT);
00650 #else
00651   if (((unsigned char) c) < 32 || ((unsigned char) c) == 127)
00652     return true;
00653   return false;
00654 #endif
00655 }
00656 
00657 inline CTypeResult
00658 ParseRules::is_mime_sep(char c)
00659 {
00660 #ifndef COMPILE_PARSE_RULES
00661   return (parseRulesCType[(unsigned char) c] & is_mime_sep_BIT);
00662 #else
00663   if ((c == '(') || (c == ')') || (c == '<') || (c == '>') || (c == '@') ||
00664       (c == ',') || (c == ';') || (c == '\\') || (c == '\"') ||
00665       (c == '/') || (c == '[') || (c == ']') || (c == '?') || (c == '{') || (c == '}') || (c == ' ') || (c == '\t'))
00666     return true;
00667   return false;
00668 #endif
00669 }
00670 
00671 inline CTypeResult
00672 ParseRules::is_http_field_name(char c)
00673 {
00674 #ifndef COMPILE_PARSE_RULES
00675   return (parseRulesCType[(unsigned char) c] & is_http_field_name_BIT);
00676 #else
00677   if ((c == ':') || (is_mime_sep(c) && (c != '@')))
00678     return false;
00679   return true;
00680 #endif
00681 }
00682 
00683 inline CTypeResult
00684 ParseRules::is_http_field_value(char c)
00685 {
00686 #ifndef COMPILE_PARSE_RULES
00687   return (CTypeResult) (parseRulesCType[(unsigned char) c] & is_http_field_value_BIT);
00688 #else
00689   switch (c) {
00690   case CHAR_CR:
00691   case CHAR_LF:
00692   case '\"':
00693   case ',':
00694     return false;
00695   }
00696   return true;
00697 #endif
00698 }
00699 
00700 //////////////////////////////////////////////////////////////////////////////
00701 //
00702 //      inline CTypeResult ParseRules::strncasecmp_eol(s1, s2, count)
00703 //
00704 //      This wacky little function compares if two strings <s1> and <s2> match
00705 //      (case-insensitively) up to <count> characters long, stopping not only
00706 //      at the end of string ('\0'), but also at end of line (CR or LF).
00707 //
00708 //////////////////////////////////////////////////////////////////////////////
00709 
00710 inline CTypeResult
00711 ParseRules::strncasecmp_eow(const char *s1, const char *s2, int count)
00712 {
00713   for (int i = 0; i < count; i++) {
00714     const char &a = s1[i];
00715     const char &b = s2[i];
00716 
00717     ///////////////////////////////////////////////////////////////
00718     // if they are different; only match if both are terminators //
00719     ///////////////////////////////////////////////////////////////
00720     if (ink_tolower(a) != ink_tolower(b))
00721       return (is_eow(a) && is_eow(b));
00722   }
00723   return (true);
00724 }
00725 
00726 //////////////////////////////////////////////////////////////////////////////
00727 //
00728 //  strlen_eow()
00729 //
00730 //  return the length of a string
00731 //////////////////////////////////////////////////////////////////////////////
00732 inline int
00733 ParseRules::strlen_eow(const char *s)
00734 {
00735   for (int i = 0; true; i++) {
00736     if (is_eow(s[i]))
00737       return (i);
00738   }
00739 }
00740 
00741 //////////////////////////////////////////////////////////////////////////////
00742 //
00743 //  strstr_eow()
00744 //
00745 //  This function is the same as strstr(), except that it accepts strings
00746 //  that are terminated with '\r', '\n' or null.
00747 //  It returns a pointer to the first occurance of s2 within s1 (or null).
00748 //////////////////////////////////////////////////////////////////////////////
00749 inline const char *
00750 ParseRules::strstr_eow(const char *s1, const char *s2)
00751 {
00752   int i1;
00753 
00754   int s2_len = strlen_eow(s2);
00755 
00756   for (i1 = 0; !is_eow(s1[i1]); i1++)
00757     if (ink_tolower(s1[i1]) == ink_tolower(s2[0]))
00758       if (strncasecmp_eow(&s1[i1], &s2[0], s2_len))
00759         return (&s1[i1]);
00760 
00761   return (0);
00762 }
00763 
00764 inline const char *
00765 ParseRules::strcasestr(const char *s1, const char *s2)
00766 {
00767   int i1;
00768 
00769   size_t s2_len = strlen(s2);
00770 
00771   for (i1 = 0; s1[i1] != '\0'; i1++)
00772     if (ink_tolower(s1[i1]) == ink_tolower(s2[0]))
00773       if (strncasecmp_eow(&s1[i1], &s2[0], (int) s2_len))
00774         return (&s1[i1]);
00775 
00776   return (0);
00777 }
00778 
00779 inline const char *
00780 ParseRules::memchr(const char *s, char c, int max_length)
00781 {
00782   for (int i = 0; i < max_length; i++)
00783     if (s[i] == c)
00784       return (&s[i]);
00785   return (0);
00786 }
00787 
00788 inline const char *
00789 ParseRules::strchr(const char *s, char c)
00790 {
00791   for (int i = 0; s[i] != '\0'; i++)
00792     if (s[i] == c)
00793       return (&s[i]);
00794   return (0);
00795 }
00796 
00797 static inline int
00798 ink_get_hex(char c)
00799 {
00800   if (ParseRules::is_digit(c))
00801     return (int) (c - '0');
00802   c = ParseRules::ink_tolower(c);
00803   return (int) ((c - 'a') + 10);
00804 }
00805 
00806 int64_t ink_atoi64(const char *);
00807 uint64_t ink_atoui64(const char *);
00808 int64_t ink_atoi64(const char *, int);
00809 
00810 
00811 static inline int
00812 ink_atoi(const char *str)
00813 {
00814   int64_t val = ink_atoi64(str);
00815 
00816   if (val > INT_MAX)
00817     return INT_MAX;
00818   else if (val < INT_MIN)
00819     return INT_MIN;
00820   else
00821     return static_cast<int>(val);
00822 }
00823 
00824 static inline int
00825 ink_atoi(const char *str, int len)
00826 {
00827   int64_t val = ink_atoi64(str, len);
00828 
00829   if (val > INT_MAX)
00830     return INT_MAX;
00831   else if (val < INT_MIN)
00832     return INT_MIN;
00833   else
00834     return static_cast<int>(val);
00835 }
00836 
00837 static inline unsigned int
00838 ink_atoui(const char *str)
00839 {
00840   uint64_t val = ink_atoui64(str);
00841 
00842   if (val > INT_MAX)
00843     return INT_MAX;
00844   else
00845     return static_cast<int>(val);
00846 }
00847 
00848 #endif /* #if !defined (_ParseRules_h_) */

Generated by  doxygen 1.7.1