1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842
|
/** @file
A brief file description
@section license License
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#if !defined(_ParseRules_h_)
#define _ParseRules_h_
#include <string.h>
#include "ts/ink_defs.h"
#include "ts/ink_apidefs.h"
#include "ts/ink_platform.h"
typedef unsigned int CTypeResult;
// Set this to 0 to disable SI
// decimal multipliers
#define USE_SI_MULTILIERS 1
#define is_char_BIT (1 << 0)
#define is_upalpha_BIT (1 << 1)
#define is_loalpha_BIT (1 << 2)
#define is_alpha_BIT (1 << 3)
#define is_digit_BIT (1 << 4)
#define is_ctl_BIT (1 << 5)
#define is_ws_BIT (1 << 6)
#define is_hex_BIT (1 << 7)
#define is_pchar_BIT (1 << 8)
#define is_extra_BIT (1 << 9)
#define is_safe_BIT (1 << 10)
#define is_unsafe_BIT (1 << 11)
#define is_national_BIT (1 << 12)
#define is_reserved_BIT (1 << 13)
#define is_unreserved_BIT (1 << 14)
#define is_punct_BIT (1 << 15)
#define is_end_of_url_BIT (1 << 16)
#define is_tspecials_BIT (1 << 17)
#define is_spcr_BIT (1 << 18)
#define is_splf_BIT (1 << 19)
#define is_wslfcr_BIT (1 << 20)
#define is_eow_BIT (1 << 21)
#define is_token_BIT (1 << 22)
#define is_wildmat_BIT (1 << 23)
#define is_sep_BIT (1 << 24)
#define is_empty_BIT (1 << 25)
#define is_alnum_BIT (1 << 26)
#define is_space_BIT (1 << 27)
#define is_control_BIT (1 << 28)
#define is_mime_sep_BIT (1 << 29)
#define is_http_field_name_BIT (1 << 30)
/* shut up the DEC compiler */
#define is_http_field_value_BIT (((CTypeResult)1) << 31)
extern ink_undoc_liapi const CTypeResult parseRulesCType[];
inkcoreapi extern const char parseRulesCTypeToUpper[];
inkcoreapi extern const char parseRulesCTypeToLower[];
class ParseRules
{
public:
ParseRules();
////////////////////////////
// whitespace definitions //
////////////////////////////
enum {
CHAR_SP = 32, /* space */
CHAR_HT = 9, /* horizontal tab */
CHAR_LF = 10, /* line feed */
CHAR_VT = 11, /* vertical tab */
CHAR_NP = 12, /* new page */
CHAR_CR = 13 /* carriage return */
};
/////////////////////
// character tests //
/////////////////////
static CTypeResult is_type(char c, uint32_t bit);
static CTypeResult is_char(char c); // ASCII 0-127
static CTypeResult is_upalpha(char c); // A-Z
static CTypeResult is_loalpha(char c); // a-z
static CTypeResult is_alpha(char c); // A-Z,a-z
static CTypeResult is_digit(char c); // 0-9
static CTypeResult is_ctl(char c); // ASCII 0-31,127 (includes ws)
static CTypeResult is_hex(char c); // 0-9,A-F,a-f
static CTypeResult is_ws(char c); // SP,HT
static CTypeResult is_cr(char c); // CR
static CTypeResult is_lf(char c); // LF
static CTypeResult is_spcr(char c); // SP,CR
static CTypeResult is_splf(char c); // SP,LF
static CTypeResult is_wslfcr(char c); // SP,HT,LF,CR
static CTypeResult is_tspecials(char c); // HTTP chars that need quoting
static CTypeResult is_token(char c); // token (not CTL or specials)
static CTypeResult is_extra(char c); // !,*,QUOT,(,),COMMA
static CTypeResult is_safe(char c); // [$-_.+]
static CTypeResult is_unsafe(char c); // SP,DBLQUOT,#,%,<,>
static CTypeResult is_national(char c); // {,},|,BACKSLASH,^,~,[,],`
static CTypeResult is_reserved(char c); // :,/,?,:,@,&,=
static CTypeResult is_unreserved(char c); // alpha,digit,safe,extra,nat.
static CTypeResult is_punct(char c); // !"#$%&'()*+,-./:;<>=?@_{}|~
static CTypeResult is_end_of_url(char c); // NUL,CR,SP
static CTypeResult is_eow(char c); // NUL,CR,LF
static CTypeResult is_wildmat(char c); // \,*,?,[
static CTypeResult is_sep(char c); // NULL,COMMA,':','!',wslfcr
static CTypeResult is_empty(char c); // wslfcr,#
static CTypeResult is_alnum(char c); // 0-9,A-Z,a-z
static CTypeResult is_space(char c); // ' ' HT,VT,NP,CR,LF
static CTypeResult is_control(char c); // 0-31 127
static CTypeResult is_mime_sep(char c); // ()<>,;\"/[]?{} \t
static CTypeResult is_http_field_name(char c); // not : or mime_sep except for @
static CTypeResult is_http_field_value(char c); // not CR, LF, comma, or "
//////////////////
// string tests //
//////////////////
static CTypeResult is_escape(const char *seq); // %<hex><hex>
static CTypeResult is_uchar(const char *seq); // starts unresrvd or is escape
static CTypeResult is_pchar(const char *seq); // uchar,:,@,&,=,+ (see code)
///////////////////
// unimplemented //
///////////////////
// static CTypeResult is_comment(const char * str);
// static CTypeResult is_ctext(const char * str);
////////////////
// operations //
////////////////
static CTypeResult strncasecmp_eow(const char *s1, const char *s2, int n);
static const char *strcasestr(const char *s1, const char *s2);
static int strlen_eow(const char *s);
static const char *strstr_eow(const char *s1, const char *s2);
static char ink_toupper(char c);
static char ink_tolower(char c);
static void ink_tolower_buffer(char *ptr, unsigned int n);
static const char *memchr(const char *s, char c, int max_length);
static const char *strchr(const char *s, char c);
private:
ParseRules(const ParseRules &);
ParseRules &operator=(const ParseRules &);
};
/* * * * * * * * * * * * * * * * * * * * * * * * * * * *
* inline functions definitions
* * * * * * * * * * * * * * * * * * * * * * * * * * * */
inline CTypeResult
ParseRules::is_type(char c, uint32_t bitmask)
{
return (parseRulesCType[(unsigned char)c] & bitmask);
}
inline CTypeResult
ParseRules::is_char(char c)
{
#ifndef COMPILE_PARSE_RULES
return (parseRulesCType[(unsigned char)c] & is_char_BIT);
#else
return ((c & 0x80) == 0);
#endif
}
inline CTypeResult
ParseRules::is_upalpha(char c)
{
#ifndef COMPILE_PARSE_RULES
return (parseRulesCType[(unsigned char)c] & is_upalpha_BIT);
#else
return (c >= 'A' && c <= 'Z');
#endif
}
inline CTypeResult
ParseRules::is_loalpha(char c)
{
#ifndef COMPILE_PARSE_RULES
return (parseRulesCType[(unsigned char)c] & is_loalpha_BIT);
#else
return (c >= 'a' && c <= 'z');
#endif
}
inline CTypeResult
ParseRules::is_alpha(char c)
{
#ifndef COMPILE_PARSE_RULES
return (parseRulesCType[(unsigned char)c] & is_alpha_BIT);
#else
return (is_upalpha(c) || is_loalpha(c));
#endif
}
inline CTypeResult
ParseRules::is_digit(char c)
{
#ifndef COMPILE_PARSE_RULES
return (parseRulesCType[(unsigned char)c] & is_digit_BIT);
#else
return (c >= '0' && c <= '9');
#endif
}
inline CTypeResult
ParseRules::is_alnum(char c)
{
#ifndef COMPILE_PARSE_RULES
return (parseRulesCType[(unsigned char)c] & is_alnum_BIT);
#else
return (is_alpha(c) || is_digit(c));
#endif
}
inline CTypeResult
ParseRules::is_ctl(char c)
{
#ifndef COMPILE_PARSE_RULES
return (parseRulesCType[(unsigned char)c] & is_ctl_BIT);
#else
return ((!(c & 0x80) && c <= 31) || c == 127);
#endif
}
inline CTypeResult
ParseRules::is_ws(char c)
{
#ifndef COMPILE_PARSE_RULES
return (parseRulesCType[(unsigned char)c] & is_ws_BIT);
#else
return (c == CHAR_SP || c == CHAR_HT);
#endif
}
inline CTypeResult
ParseRules::is_hex(char c)
{
#ifndef COMPILE_PARSE_RULES
return (parseRulesCType[(unsigned char)c] & is_hex_BIT);
#else
return ((c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f') || (c >= '0' && c <= '9'));
#endif
}
inline CTypeResult
ParseRules::is_cr(char c)
{
return (c == CHAR_CR);
}
inline CTypeResult
ParseRules::is_lf(char c)
{
return (c == CHAR_LF);
}
inline CTypeResult
ParseRules::is_splf(char c)
{
#ifndef COMPILE_PARSE_RULES
return (parseRulesCType[(unsigned char)c] & is_splf_BIT);
#else
return (c == CHAR_SP || c == CHAR_LF);
#endif
}
inline CTypeResult
ParseRules::is_spcr(char c)
{
#ifndef COMPILE_PARSE_RULES
return (parseRulesCType[(unsigned char)c] & is_spcr_BIT);
#else
return (c == CHAR_SP || c == CHAR_CR);
#endif
}
inline CTypeResult
ParseRules::is_wslfcr(char c)
{
#ifndef COMPILE_PARSE_RULES
return (parseRulesCType[(unsigned char)c] & is_wslfcr_BIT);
#else
return ParseRules::is_ws(c) || ParseRules::is_splf(c) || ParseRules::is_spcr(c);
#endif
}
inline CTypeResult
ParseRules::is_extra(char c)
{
#ifndef COMPILE_PARSE_RULES
return (parseRulesCType[(unsigned char)c] & is_extra_BIT);
#else
switch (c) {
case '!':
case '*':
case '\'':
case '(':
case ')':
case ',':
return (true);
}
return (false);
#endif
}
inline CTypeResult
ParseRules::is_safe(char c)
{
#ifndef COMPILE_PARSE_RULES
return (parseRulesCType[(unsigned char)c] & is_safe_BIT);
#else
return (c == '$' || c == '-' || c == '_' || c == '.' || c == '+');
#endif
}
inline CTypeResult
ParseRules::is_unsafe(char c)
{
#ifndef COMPILE_PARSE_RULES
return (parseRulesCType[(unsigned char)c] & is_unsafe_BIT);
#else
if (is_ctl(c))
return (true);
switch (c) {
case ' ':
case '\"':
case '#':
case '%':
case '<':
case '>':
return (true);
}
return (false);
#endif
}
inline CTypeResult
ParseRules::is_reserved(char c)
{
#ifndef COMPILE_PARSE_RULES
return (parseRulesCType[(unsigned char)c] & is_reserved_BIT);
#else
switch (c) {
case ';':
case '/':
case '?':
case ':':
case '@':
case '&':
case '=':
return (true);
}
return (false);
#endif
}
inline CTypeResult
ParseRules::is_national(char c)
{
#ifndef COMPILE_PARSE_RULES
return (parseRulesCType[(unsigned char)c] & is_national_BIT);
#else
switch (c) {
case '{':
case '}':
case '|':
case '\\':
case '^':
case '~':
case '[':
case ']':
case '`':
return (true);
}
return (false);
#endif
}
inline CTypeResult
ParseRules::is_unreserved(char c)
{
#ifndef COMPILE_PARSE_RULES
return (parseRulesCType[(unsigned char)c] & is_unreserved_BIT);
#else
return (is_alpha(c) || is_digit(c) || is_safe(c) || is_extra(c) || is_national(c));
#endif
}
inline CTypeResult
ParseRules::is_punct(char c)
{
#ifndef COMPILE_PARSE_RULES
return (parseRulesCType[(unsigned char)c] & is_punct_BIT);
#else
switch (c) {
case '!':
case '"':
case '#':
case '%':
case '&':
case '\'':
case '(':
case ')':
case '*':
case '+':
case ',':
case '-':
case '.':
case '/':
case ':':
case ';':
case '<':
case '=':
case '>':
case '?':
case '@':
case '[':
case '\\':
case ']':
case '^':
case '_':
case '`':
case '{':
case '|':
case '}':
case '~':
return (true);
}
return (false);
#endif
}
inline CTypeResult
ParseRules::is_end_of_url(char c)
{
#ifndef COMPILE_PARSE_RULES
return (parseRulesCType[(unsigned char)c] & is_end_of_url_BIT);
#else
return (c == '\0' || c == '\n' || c == ' ' || ParseRules::is_ctl(c));
#endif
}
inline CTypeResult
ParseRules::is_escape(const char *seq)
{
return (seq[0] == '%' && is_hex(seq[1]) && is_hex(seq[2]));
}
inline CTypeResult
ParseRules::is_uchar(const char *seq)
{
return (is_unreserved(seq[0]) || is_escape(seq));
}
//
// have to cheat on this one
//
inline CTypeResult
ParseRules::is_pchar(const char *seq)
{
#ifndef COMPILE_PARSE_RULES
if (*seq != '%')
return (parseRulesCType[(uint8_t)*seq] & is_pchar_BIT);
else
return is_hex(seq[1]) && is_hex(seq[2]);
#else
if (is_unreserved(*seq))
return (true);
switch (seq[0]) {
case ':':
case '@':
case '&':
case '=':
case '+':
return (true);
}
return (false);
#endif
}
inline CTypeResult
ParseRules::is_tspecials(char c)
{
#ifndef COMPILE_PARSE_RULES
return (parseRulesCType[(unsigned char)c] & is_tspecials_BIT);
#else
switch (c) {
case '(':
case ')':
case '<':
case '>':
case '@':
case ',':
case ';':
case ':':
case '\\':
case '"':
case '/':
case '[':
case ']':
case '?':
case '=':
case '{':
case '}':
case CHAR_SP:
case CHAR_HT:
return (true);
}
return (false);
#endif
}
inline CTypeResult
ParseRules::is_token(char c)
{
#ifndef COMPILE_PARSE_RULES
return (parseRulesCType[(unsigned char)c] & is_token_BIT);
#else
return (is_char(c) && !(is_ctl(c) || is_tspecials(c)));
#endif
}
inline char
ParseRules::ink_toupper(char c)
{
#ifndef COMPILE_PARSE_RULES
return parseRulesCTypeToUpper[(unsigned char)c];
#else
int up_case = c;
const int up_case_diff = 'a' - 'A';
if (c >= 'a' && c <= 'z') {
up_case = c - up_case_diff;
}
return (up_case);
#endif
}
inline char
ParseRules::ink_tolower(char c)
{
#ifndef COMPILE_PARSE_RULES
return parseRulesCTypeToLower[(unsigned char)c];
#else
int lo_case = c;
const int lo_case_diff = 'a' - 'A';
if (c >= 'A' && c <= 'Z') {
lo_case = c + lo_case_diff;
}
return (lo_case);
#endif
}
inline CTypeResult
ParseRules::is_eow(char c)
{
#ifndef COMPILE_PARSE_RULES
return (parseRulesCType[(unsigned char)c] & is_eow_BIT);
#else
return (c == '\0' || c == '\r' || c == '\n');
#endif
}
inline CTypeResult
ParseRules::is_wildmat(char c)
{
#ifndef COMPILE_PARSE_RULES
return (parseRulesCType[(unsigned char)c] & is_wildmat_BIT);
#else
return (c == '*' || c == '?' || c == '[' || c == '\\');
#endif
}
inline CTypeResult
ParseRules::is_sep(char c)
{
#ifndef COMPILE_PARSE_RULES
return (parseRulesCType[(unsigned char)c] & is_sep_BIT);
#else
return (!c || c == ',' || c == ':' || c == '!' || is_wslfcr(c));
#endif
}
inline CTypeResult
ParseRules::is_empty(char c)
{
#ifndef COMPILE_PARSE_RULES
return (parseRulesCType[(unsigned char)c] & is_empty_BIT);
#else
return (c == '#' || is_wslfcr(c));
#endif
}
inline CTypeResult
ParseRules::is_space(char c)
{
#ifndef COMPILE_PARSE_RULES
return (parseRulesCType[(unsigned char)c] & is_space_BIT);
#else
switch (c) {
case CHAR_SP:
case CHAR_HT:
case CHAR_LF:
case CHAR_VT:
case CHAR_NP:
case CHAR_CR:
return (true);
}
return (false);
#endif
}
inline CTypeResult
ParseRules::is_control(char c)
{
#ifndef COMPILE_PARSE_RULES
return (parseRulesCType[(unsigned char)c] & is_control_BIT);
#else
if (((unsigned char)c) < 32 || ((unsigned char)c) == 127)
return true;
return false;
#endif
}
inline CTypeResult
ParseRules::is_mime_sep(char c)
{
#ifndef COMPILE_PARSE_RULES
return (parseRulesCType[(unsigned char)c] & is_mime_sep_BIT);
#else
if ((c == '(') || (c == ')') || (c == '<') || (c == '>') || (c == '@') || (c == ',') || (c == ';') || (c == '\\') ||
(c == '\"') || (c == '/') || (c == '[') || (c == ']') || (c == '?') || (c == '{') || (c == '}') || (c == ' ') || (c == '\t'))
return true;
return false;
#endif
}
inline CTypeResult
ParseRules::is_http_field_name(char c)
{
#ifndef COMPILE_PARSE_RULES
return (parseRulesCType[(unsigned char)c] & is_http_field_name_BIT);
#else
if ((c == ':') || (is_mime_sep(c) && (c != '@')))
return false;
return true;
#endif
}
inline CTypeResult
ParseRules::is_http_field_value(char c)
{
#ifndef COMPILE_PARSE_RULES
return (CTypeResult)(parseRulesCType[(unsigned char)c] & is_http_field_value_BIT);
#else
switch (c) {
case CHAR_CR:
case CHAR_LF:
case '\"':
case ',':
return false;
}
return true;
#endif
}
//////////////////////////////////////////////////////////////////////////////
//
// inline CTypeResult ParseRules::strncasecmp_eol(s1, s2, count)
//
// This wacky little function compares if two strings <s1> and <s2> match
// (case-insensitively) up to <count> characters long, stopping not only
// at the end of string ('\0'), but also at end of line (CR or LF).
//
//////////////////////////////////////////////////////////////////////////////
inline CTypeResult
ParseRules::strncasecmp_eow(const char *s1, const char *s2, int count)
{
for (int i = 0; i < count; i++) {
const char &a = s1[i];
const char &b = s2[i];
///////////////////////////////////////////////////////////////
// if they are different; only match if both are terminators //
///////////////////////////////////////////////////////////////
if (ink_tolower(a) != ink_tolower(b))
return (is_eow(a) && is_eow(b));
}
return (true);
}
//////////////////////////////////////////////////////////////////////////////
//
// strlen_eow()
//
// return the length of a string
//////////////////////////////////////////////////////////////////////////////
inline int
ParseRules::strlen_eow(const char *s)
{
for (int i = 0; true; i++) {
if (is_eow(s[i]))
return (i);
}
}
//////////////////////////////////////////////////////////////////////////////
//
// strstr_eow()
//
// This function is the same as strstr(), except that it accepts strings
// that are terminated with '\r', '\n' or null.
// It returns a pointer to the first occurance of s2 within s1 (or null).
//////////////////////////////////////////////////////////////////////////////
inline const char *
ParseRules::strstr_eow(const char *s1, const char *s2)
{
int i1;
int s2_len = strlen_eow(s2);
for (i1 = 0; !is_eow(s1[i1]); i1++)
if (ink_tolower(s1[i1]) == ink_tolower(s2[0]))
if (strncasecmp_eow(&s1[i1], &s2[0], s2_len))
return (&s1[i1]);
return (0);
}
inline const char *
ParseRules::strcasestr(const char *s1, const char *s2)
{
int i1;
size_t s2_len = strlen(s2);
for (i1 = 0; s1[i1] != '\0'; i1++)
if (ink_tolower(s1[i1]) == ink_tolower(s2[0]))
if (strncasecmp_eow(&s1[i1], &s2[0], (int)s2_len))
return (&s1[i1]);
return (0);
}
inline const char *
ParseRules::memchr(const char *s, char c, int max_length)
{
for (int i = 0; i < max_length; i++)
if (s[i] == c)
return (&s[i]);
return (0);
}
inline const char *
ParseRules::strchr(const char *s, char c)
{
for (int i = 0; s[i] != '\0'; i++)
if (s[i] == c)
return (&s[i]);
return (0);
}
static inline int
ink_get_hex(char c)
{
if (ParseRules::is_digit(c))
return (int)(c - '0');
c = ParseRules::ink_tolower(c);
return (int)((c - 'a') + 10);
}
int64_t ink_atoi64(const char *);
uint64_t ink_atoui64(const char *);
int64_t ink_atoi64(const char *, int);
static inline int
ink_atoi(const char *str)
{
int64_t val = ink_atoi64(str);
if (val > INT_MAX)
return INT_MAX;
else if (val < INT_MIN)
return INT_MIN;
else
return static_cast<int>(val);
}
static inline int
ink_atoi(const char *str, int len)
{
int64_t val = ink_atoi64(str, len);
if (val > INT_MAX)
return INT_MAX;
else if (val < INT_MIN)
return INT_MIN;
else
return static_cast<int>(val);
}
static inline unsigned int
ink_atoui(const char *str)
{
uint64_t val = ink_atoui64(str);
if (val > INT_MAX)
return INT_MAX;
else
return static_cast<int>(val);
}
#endif /* #if !defined (_ParseRules_h_) */
|