001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 * 019 */ 020package org.apache.directory.api.util; 021 022 023/** 024 * Various Character methods are kept here. 025 * 026 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 027 */ 028public final class Chars 029{ 030 /** <alpha> ::= [0x41-0x5A] | [0x61-0x7A] */ 031 private static final boolean[] ALPHA = 032 { 033 false, false, false, false, false, false, false, false, 034 false, false, false, false, false, false, false, false, 035 false, false, false, false, false, false, false, false, 036 false, false, false, false, false, false, false, false, 037 false, false, false, false, false, false, false, false, 038 false, false, false, false, false, false, false, false, 039 false, false, false, false, false, false, false, false, 040 false, false, false, false, false, false, false, false, 041 false, true, true, true, true, true, true, true, 042 true, true, true, true, true, true, true, true, 043 true, true, true, true, true, true, true, true, 044 true, true, true, false, false, false, false, false, 045 false, true, true, true, true, true, true, true, 046 true, true, true, true, true, true, true, true, 047 true, true, true, true, true, true, true, true, 048 true, true, true, false, false, false, false, false 049 }; 050 051 /** <alpha-lower-case> ::= [0x61-0x7A] */ 052 private static final boolean[] ALPHA_LOWER_CASE = 053 { 054 false, false, false, false, false, false, false, false, 055 false, false, false, false, false, false, false, false, 056 false, false, false, false, false, false, false, false, 057 false, false, false, false, false, false, false, false, 058 false, false, false, false, false, false, false, false, 059 false, false, false, false, false, false, false, false, 060 false, false, false, false, false, false, false, false, 061 false, false, false, false, false, false, false, false, 062 false, false, false, false, false, false, false, false, 063 false, false, false, false, false, false, false, false, 064 false, false, false, false, false, false, false, false, 065 false, false, false, false, false, false, false, false, 066 false, true, true, true, true, true, true, true, 067 true, true, true, true, true, true, true, true, 068 true, true, true, true, true, true, true, true, 069 true, true, true, false, false, false, false, false 070 }; 071 072 /** <alpha-upper-case> ::= [0x41-0x5A] */ 073 private static final boolean[] ALPHA_UPPER_CASE = 074 { 075 false, false, false, false, false, false, false, false, 076 false, false, false, false, false, false, false, false, 077 false, false, false, false, false, false, false, false, 078 false, false, false, false, false, false, false, false, 079 false, false, false, false, false, false, false, false, 080 false, false, false, false, false, false, false, false, 081 false, false, false, false, false, false, false, false, 082 false, false, false, false, false, false, false, false, 083 false, true, true, true, true, true, true, true, 084 true, true, true, true, true, true, true, true, 085 true, true, true, true, true, true, true, true, 086 true, true, true, false, false, false, false, false, 087 false, false, false, false, false, false, false, false, 088 false, false, false, false, false, false, false, false, 089 false, false, false, false, false, false, false, false, 090 false, false, false, false, false, false, false, false, 091 }; 092 093 /** <alpha-digit> | <digit> */ 094 private static final boolean[] ALPHA_DIGIT = 095 { 096 false, false, false, false, false, false, false, false, 097 false, false, false, false, false, false, false, false, 098 false, false, false, false, false, false, false, false, 099 false, false, false, false, false, false, false, false, 100 false, false, false, false, false, false, false, false, 101 false, false, false, false, false, false, false, false, 102 true, true, true, true, true, true, true, true, 103 true, true, false, false, false, false, false, false, 104 false, true, true, true, true, true, true, true, 105 true, true, true, true, true, true, true, true, 106 true, true, true, true, true, true, true, true, 107 true, true, true, false, false, false, false, false, 108 false, true, true, true, true, true, true, true, 109 true, true, true, true, true, true, true, true, 110 true, true, true, true, true, true, true, true, 111 true, true, true, false, false, false, false, false 112 }; 113 114 /** <alpha> | <digit> | '-' */ 115 private static final boolean[] CHAR = 116 { 117 false, false, false, false, false, false, false, false, 118 false, false, false, false, false, false, false, false, 119 false, false, false, false, false, false, false, false, 120 false, false, false, false, false, false, false, false, 121 false, false, false, false, false, false, false, false, 122 false, false, false, false, false, true, false, false, 123 true, true, true, true, true, true, true, true, 124 true, true, false, false, false, false, false, false, 125 false, true, true, true, true, true, true, true, 126 true, true, true, true, true, true, true, true, 127 true, true, true, true, true, true, true, true, 128 true, true, true, false, false, false, false, false, 129 false, true, true, true, true, true, true, true, 130 true, true, true, true, true, true, true, true, 131 true, true, true, true, true, true, true, true, 132 true, true, true, false, false, false, false, false 133 }; 134 135 /** '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' */ 136 private static final boolean[] DIGIT = 137 { 138 false, false, false, false, false, false, false, false, 139 false, false, false, false, false, false, false, false, 140 false, false, false, false, false, false, false, false, 141 false, false, false, false, false, false, false, false, 142 false, false, false, false, false, false, false, false, 143 false, false, false, false, false, false, false, false, 144 true, true, true, true, true, true, true, true, 145 true, true, false, false, false, false, false, false, 146 false, false, false, false, false, false, false, false, 147 false, false, false, false, false, false, false, false, 148 false, false, false, false, false, false, false, false, 149 false, false, false, false, false, false, false, false, 150 false, false, false, false, false, false, false, false, 151 false, false, false, false, false, false, false, false, 152 false, false, false, false, false, false, false, false, 153 false, false, false, false, false, false, false, false 154 }; 155 156 /** <hex> ::= [0x30-0x39] | [0x41-0x46] | [0x61-0x66] */ 157 private static final boolean[] HEX = 158 { 159 false, false, false, false, false, false, false, false, 160 false, false, false, false, false, false, false, false, 161 false, false, false, false, false, false, false, false, 162 false, false, false, false, false, false, false, false, 163 false, false, false, false, false, false, false, false, 164 false, false, false, false, false, false, false, false, 165 true, true, true, true, true, true, true, true, 166 true, true, false, false, false, false, false, false, 167 false, true, true, true, true, true, true, false, 168 false, false, false, false, false, false, false, false, 169 false, false, false, false, false, false, false, false, 170 false, false, false, false, false, false, false, false, 171 false, true, true, true, true, true, true, false, 172 false, false, false, false, false, false, false, false, 173 false, false, false, false, false, false, false, false, 174 false, false, false, false, false, false, false, false 175 }; 176 177 178 private Chars() 179 { 180 } 181 182 183 /** 184 * Test if the current character is equal to a specific character. 185 * 186 * @param chars The buffer which contains the data 187 * @param index 188 * Current position in the buffer 189 * @param car The character we want to compare with the current buffer position 190 * @return <code>true</code> if the current character equals the given character. 191 */ 192 public static boolean isCharASCII( char[] chars, int index, char car ) 193 { 194 if ( ( chars == null ) || ( chars.length == 0 ) || ( index < 0 ) || ( index >= chars.length ) ) 195 { 196 return false; 197 } 198 else 199 { 200 return chars[index] == car; 201 } 202 } 203 204 205 /** 206 * Test if the current character is equal to a specific character. 207 * 208 * @param string The String which contains the data 209 * @param index Current position in the string 210 * @param car The character we want to compare with the current string 211 * position 212 * @return <code>true</code> if the current character equals the given 213 * character. 214 */ 215 public static boolean isCharASCII( String string, int index, char car ) 216 { 217 if ( string == null ) 218 { 219 return false; 220 } 221 222 int length = string.length(); 223 224 if ( ( length == 0 ) || ( index < 0 ) || ( index >= length ) ) 225 { 226 return false; 227 } 228 else 229 { 230 return string.charAt( index ) == car; 231 } 232 } 233 234 235 /** 236 * Test if the current character is equal to a specific character. 237 * 238 * @param string The String which contains the data 239 * @param index Current position in the string 240 * @param car The character we want to compare with the current string 241 * position 242 * @return <code>true</code> if the current character equals the given 243 * character. 244 */ 245 public static boolean isICharASCII( String string, int index, char car ) 246 { 247 if ( string == null ) 248 { 249 return false; 250 } 251 252 int length = string.length(); 253 254 if ( ( length == 0 ) || ( index < 0 ) || ( index >= length ) ) 255 { 256 return false; 257 } 258 else 259 { 260 return ( ( string.charAt( index ) | 0x20 ) & car ) == car; 261 } 262 } 263 264 265 /** 266 * Test if the current character is equal to a specific character. 267 * 268 * @param bytes The String which contains the data 269 * @param index Current position in the string 270 * @param car The character we want to compare with the current string 271 * position 272 * @return <code>true</code> if the current character equals the given 273 * character. 274 */ 275 public static boolean isICharASCII( byte[] bytes, int index, char car ) 276 { 277 if ( bytes == null ) 278 { 279 return false; 280 } 281 282 int length = bytes.length; 283 284 if ( ( length == 0 ) || ( index < 0 ) || ( index >= length ) ) 285 { 286 return false; 287 } 288 else 289 { 290 return ( ( bytes[index] | 0x20 ) & car ) == car; 291 } 292 } 293 294 295 /** 296 * Test if the current byte is an Alpha character : 297 * <alpha> ::= [0x41-0x5A] | [0x61-0x7A] 298 * 299 * @param c The byte to test 300 * 301 * @return <code>true</code> if the byte is an Alpha 302 * character 303 */ 304 public static boolean isAlpha( byte c ) 305 { 306 return ( c > 0 ) && ( c <= 127 ) && ALPHA[c]; 307 } 308 309 310 /** 311 * Test if the current character is an Alpha character : 312 * <alpha> ::= [0x41-0x5A] | [0x61-0x7A] 313 * 314 * @param c The char to test 315 * 316 * @return <code>true</code> if the character is an Alpha 317 * character 318 */ 319 public static boolean isAlpha( char c ) 320 { 321 return ( c > 0 ) && ( c <= 127 ) && ALPHA[c]; 322 } 323 324 325 /** 326 * Test if the current character is an Alpha character : <alpha> ::= 327 * [0x41-0x5A] | [0x61-0x7A] 328 * 329 * @param bytes The buffer which contains the data 330 * @param index Current position in the buffer 331 * @return <code>true</code> if the current character is an Alpha 332 * character 333 */ 334 public static boolean isAlphaASCII( byte[] bytes, int index ) 335 { 336 if ( ( bytes == null ) || ( bytes.length == 0 ) || ( index < 0 ) || ( index >= bytes.length ) ) 337 { 338 return false; 339 } 340 else 341 { 342 byte c = bytes[index]; 343 344 return ( ( c | 0x7F ) == 0x7F ) && ALPHA[c]; 345 } 346 } 347 348 349 /** 350 * Test if the current character is an Alpha character : <alpha> ::= 351 * [0x41-0x5A] | [0x61-0x7A] 352 * 353 * @param chars The buffer which contains the data 354 * @param index Current position in the buffer 355 * @return <code>true</code> if the current character is an Alpha 356 * character 357 */ 358 public static boolean isAlphaASCII( char[] chars, int index ) 359 { 360 if ( ( chars == null ) || ( chars.length == 0 ) || ( index < 0 ) || ( index >= chars.length ) ) 361 { 362 return false; 363 } 364 else 365 { 366 char c = chars[index]; 367 368 return ( ( c | 0x007F ) == 0x007F ) && ALPHA[c]; 369 } 370 } 371 372 373 /** 374 * Test if the current character is an Alpha character : <alpha> ::= 375 * [0x41-0x5A] | [0x61-0x7A] 376 * 377 * @param string The string which contains the data 378 * @param index Current position in the string 379 * @return <code>true</code> if the current character is an Alpha 380 * character 381 */ 382 public static boolean isAlphaASCII( String string, int index ) 383 { 384 if ( string == null ) 385 { 386 return false; 387 } 388 389 int length = string.length(); 390 391 if ( ( length == 0 ) || ( index < 0 ) || ( index >= length ) ) 392 { 393 return false; 394 } 395 else 396 { 397 char c = string.charAt( index ); 398 399 return ( ( c | 0x007F ) == 0x007F ) && ALPHA[c]; 400 } 401 } 402 403 404 /** 405 * Test if the current character is a lowercased Alpha character : <br> 406 * <alpha> ::= [0x61-0x7A] 407 * 408 * @param string The string which contains the data 409 * @param index Current position in the string 410 * @return <code>true</code> if the current character is a lower Alpha 411 * character 412 */ 413 public static boolean isAlphaLowercaseASCII( String string, int index ) 414 { 415 if ( string == null ) 416 { 417 return false; 418 } 419 420 int length = string.length(); 421 422 if ( ( length == 0 ) || ( index < 0 ) || ( index >= length ) ) 423 { 424 return false; 425 } 426 else 427 { 428 char c = string.charAt( index ); 429 430 return ( ( c | 0x007F ) == 0x007F ) && ALPHA_LOWER_CASE[c]; 431 } 432 } 433 434 435 /** 436 * Test if the current character is a uppercased Alpha character : <br> 437 * <alpha> ::= [0x61-0x7A] 438 * 439 * @param string The string which contains the data 440 * @param index Current position in the string 441 * @return <code>true</code> if the current character is a lower Alpha 442 * character 443 */ 444 public static boolean isAlphaUppercaseASCII( String string, int index ) 445 { 446 if ( string == null ) 447 { 448 return false; 449 } 450 451 int length = string.length(); 452 453 if ( ( length == 0 ) || ( index < 0 ) || ( index >= length ) ) 454 { 455 return false; 456 } 457 else 458 { 459 char c = string.charAt( index ); 460 461 return ( c <= 127 ) && ALPHA_UPPER_CASE[c]; 462 } 463 } 464 465 466 /** 467 * Check if the current character is an 7 bits ASCII CHAR (between 0 and 468 * 127). 469 * <char> ::= <alpha> | <digit> 470 * 471 * @param string The string which contains the data 472 * @param index Current position in the string 473 * @return The position of the next character, if the current one is a CHAR. 474 */ 475 public static boolean isAlphaDigit( String string, int index ) 476 { 477 if ( string == null ) 478 { 479 return false; 480 } 481 482 int length = string.length(); 483 484 if ( ( length == 0 ) || ( index < 0 ) || ( index >= length ) ) 485 { 486 return false; 487 } 488 else 489 { 490 char c = string.charAt( index ); 491 492 return ( c <= 127 ) && ALPHA_DIGIT[c]; 493 } 494 } 495 496 497 /** 498 * Check if the current character is an 7 bits ASCII CHAR (between 0 and 499 * 127). <char> ::= <alpha> | <digit> | '-' 500 * 501 * @param bytes The buffer which contains the data 502 * @param index Current position in the buffer 503 * @return The position of the next character, if the current one is a CHAR. 504 */ 505 public static boolean isAlphaDigitMinus( byte[] bytes, int index ) 506 { 507 if ( ( bytes == null ) || ( bytes.length == 0 ) || ( index < 0 ) || ( index >= bytes.length ) ) 508 { 509 return false; 510 } 511 else 512 { 513 byte c = bytes[index]; 514 515 return ( ( c | 0x7F ) == 0x7F ) && CHAR[c]; 516 } 517 } 518 519 520 /** 521 * Check if the current character is an 7 bits ASCII CHAR (between 0 and 522 * 127). <char> ::= <alpha> | <digit> | '-' 523 * 524 * @param chars The buffer which contains the data 525 * @param index Current position in the buffer 526 * @return The position of the next character, if the current one is a CHAR. 527 */ 528 public static boolean isAlphaDigitMinus( char[] chars, int index ) 529 { 530 if ( ( chars == null ) || ( chars.length == 0 ) || ( index < 0 ) || ( index >= chars.length ) ) 531 { 532 return false; 533 } 534 else 535 { 536 char c = chars[index]; 537 538 return ( c <= 127 ) && CHAR[c]; 539 } 540 } 541 542 543 /** 544 * Check if the current character is an 7 bits ASCII CHAR (between 0 and 545 * 127). <char> ::= <alpha> | <digit> | '-' 546 * 547 * @param string The string which contains the data 548 * @param index Current position in the string 549 * @return The position of the next character, if the current one is a CHAR. 550 */ 551 public static boolean isAlphaDigitMinus( String string, int index ) 552 { 553 if ( string == null ) 554 { 555 return false; 556 } 557 558 int length = string.length(); 559 560 if ( ( length == 0 ) || ( index < 0 ) || ( index >= length ) ) 561 { 562 return false; 563 } 564 else 565 { 566 char c = string.charAt( index ); 567 568 return ( c <= 127 ) && CHAR[c]; 569 } 570 } 571 572 573 /** 574 * Check if the current character is an 7 bits ASCII CHAR (between 0 and 575 * 127). <char> ::= <alpha> | <digit> | '-' 576 * 577 * @param c The char we want to check 578 * @return The position of the next character, if the current one is a CHAR. 579 */ 580 public static boolean isAlphaDigitMinus( char c ) 581 { 582 return ( ( c & 0x007F ) == c ) && CHAR[c]; 583 } 584 585 586 /** 587 * Test if the current character is a bit, ie 0 or 1. 588 * 589 * @param string 590 * The String which contains the data 591 * @param index 592 * Current position in the string 593 * @return <code>true</code> if the current character is a bit (0 or 1) 594 */ 595 public static boolean isBit( String string, int index ) 596 { 597 if ( string == null ) 598 { 599 return false; 600 } 601 602 int length = string.length(); 603 604 if ( ( length == 0 ) || ( index < 0 ) || ( index >= length ) ) 605 { 606 return false; 607 } 608 else 609 { 610 char c = string.charAt( index ); 611 return ( c == '0' ) || ( c == '1' ); 612 } 613 } 614 615 616 /** 617 * Test if the current character is a digit <digit> ::= '0' | '1' | '2' | 618 * '3' | '4' | '5' | '6' | '7' | '8' | '9' 619 * 620 * @param bytes The buffer which contains the data 621 * @return <code>true</code> if the current character is a Digit 622 */ 623 public static boolean isDigit( byte[] bytes ) 624 { 625 if ( ( bytes == null ) || ( bytes.length == 0 ) ) 626 { 627 return false; 628 } 629 else 630 { 631 return ( ( bytes[0] | 0x7F ) == 0x7F ) && DIGIT[bytes[0]]; 632 } 633 } 634 635 636 /** 637 * Test if the current character is a digit <digit> ::= '0' | '1' | '2' | 638 * '3' | '4' | '5' | '6' | '7' | '8' | '9' 639 * 640 * @param car the character to test 641 * 642 * @return <code>true</code> if the character is a Digit 643 */ 644 public static boolean isDigit( char car ) 645 { 646 return ( car >= '0' ) && ( car <= '9' ); 647 } 648 649 650 /** 651 * Test if the current byte is a digit <digit> ::= '0' | '1' | '2' | 652 * '3' | '4' | '5' | '6' | '7' | '8' | '9' 653 * 654 * @param car the byte to test 655 * 656 * @return <code>true</code> if the character is a Digit 657 */ 658 public static boolean isDigit( byte car ) 659 { 660 return ( car >= '0' ) && ( car <= '9' ); 661 } 662 663 664 /** 665 * Test if the current character is a digit <digit> ::= '0' | '1' | '2' | 666 * '3' | '4' | '5' | '6' | '7' | '8' | '9' 667 * 668 * @param bytes The buffer which contains the data 669 * @param index Current position in the buffer 670 * @return <code>true</code> if the current character is a Digit 671 */ 672 public static boolean isDigit( byte[] bytes, int index ) 673 { 674 if ( ( bytes == null ) || ( bytes.length == 0 ) || ( index < 0 ) || ( index >= bytes.length ) ) 675 { 676 return false; 677 } 678 else 679 { 680 return ( ( bytes[index] | 0x7F ) == 0x7F ) && DIGIT[bytes[index]]; 681 } 682 } 683 684 685 /** 686 * Test if the current character is a digit <digit> ::= '0' | '1' | '2' | 687 * '3' | '4' | '5' | '6' | '7' | '8' | '9' 688 * 689 * @param chars The buffer which contains the data 690 * @param index Current position in the buffer 691 * @return <code>true</code> if the current character is a Digit 692 */ 693 public static boolean isDigit( char[] chars, int index ) 694 { 695 if ( ( chars == null ) || ( chars.length == 0 ) || ( index < 0 ) || ( index >= chars.length ) ) 696 { 697 return false; 698 } 699 else 700 { 701 return ( chars[index] <= 127 ) && DIGIT[chars[index]]; 702 } 703 } 704 705 706 /** 707 * Test if the current character is a digit <digit> ::= '0' | '1' | '2' | 708 * '3' | '4' | '5' | '6' | '7' | '8' | '9' 709 * 710 * @param string The string which contains the data 711 * @param index Current position in the string 712 * @return <code>true</code> if the current character is a Digit 713 */ 714 public static boolean isDigit( String string, int index ) 715 { 716 if ( string == null ) 717 { 718 return false; 719 } 720 721 int length = string.length(); 722 723 if ( ( length == 0 ) || ( index < 0 ) || ( index >= length ) ) 724 { 725 return false; 726 } 727 else 728 { 729 char c = string.charAt( index ); 730 731 return ( c <= 127 ) && DIGIT[c]; 732 } 733 } 734 735 736 /** 737 * Test if the current character is a digit <digit> ::= '0' | '1' | '2' | 738 * '3' | '4' | '5' | '6' | '7' | '8' | '9' 739 * 740 * @param chars The buffer which contains the data 741 * @return <code>true</code> if the current character is a Digit 742 */ 743 public static boolean isDigit( char[] chars ) 744 { 745 if ( ( chars == null ) || ( chars.length == 0 ) ) 746 { 747 return false; 748 } 749 else 750 { 751 return ( chars[0] <= 127 ) && DIGIT[chars[0]]; 752 } 753 } 754 755 756 /** 757 * Check if the current char is an Hex Char 758 * <hex> ::= [0x30-0x39] | [0x41-0x46] | [0x61-0x66] 759 * 760 * @param c The char we want to check 761 * @return <code>true</code> if the current char is a Hex char 762 */ 763 public static boolean isHex( char c ) 764 { 765 return ( ( c | 0x007F ) == 0x007F ) && HEX[c]; 766 } 767 768 769 /** 770 * Check if the current byte is an Hex Char 771 * <hex> ::= [0x30-0x39] | [0x41-0x46] | [0x61-0x66] 772 * 773 * @param b The byte we want to check 774 * @return <code>true</code> if the current byte is a Hex byte 775 */ 776 public static boolean isHex( byte b ) 777 { 778 return ( ( b | 0x7F ) == 0x7F ) && HEX[b]; 779 } 780 781 782 /** 783 * Check if the current character is an Hex Char <hex> ::= [0x30-0x39] | 784 * [0x41-0x46] | [0x61-0x66] 785 * 786 * @param bytes The buffer which contains the data 787 * @param index Current position in the buffer 788 * @return <code>true</code> if the current character is a Hex Char 789 */ 790 public static boolean isHex( byte[] bytes, int index ) 791 { 792 if ( ( bytes == null ) || ( bytes.length == 0 ) || ( index < 0 ) || ( index >= bytes.length ) ) 793 { 794 return false; 795 } 796 else 797 { 798 byte c = bytes[index]; 799 800 return ( ( c | 0x7F ) == 0x7F ) && HEX[c]; 801 } 802 } 803 804 805 /** 806 * Check if the current character is an Hex Char <hex> ::= [0x30-0x39] | 807 * [0x41-0x46] | [0x61-0x66] 808 * 809 * @param chars The buffer which contains the data 810 * @param index Current position in the buffer 811 * @return <code>true</code> if the current character is a Hex Char 812 */ 813 public static boolean isHex( char[] chars, int index ) 814 { 815 if ( ( chars == null ) || ( chars.length == 0 ) || ( index < 0 ) || ( index >= chars.length ) ) 816 { 817 return false; 818 } 819 else 820 { 821 char c = chars[index]; 822 823 return ( ( c | 0x007F ) == 0x007F ) && HEX[c]; 824 } 825 } 826 827 828 /** 829 * Check if the current character is an Hex Char <hex> ::= [0x30-0x39] | 830 * [0x41-0x46] | [0x61-0x66] 831 * 832 * @param string The string which contains the data 833 * @param index Current position in the string 834 * @return <code>true</code> if the current character is a Hex Char 835 */ 836 public static boolean isHex( String string, int index ) 837 { 838 if ( string == null ) 839 { 840 return false; 841 } 842 843 int length = string.length(); 844 845 if ( ( length == 0 ) || ( index < 0 ) || ( index >= length ) ) 846 { 847 return false; 848 } 849 else 850 { 851 char c = string.charAt( index ); 852 853 return ( ( c | 0x007F ) == 0x007F ) && HEX[c]; 854 } 855 } 856 857 858 /** 859 * Check if the current character is the ASCII character underscore 0x5F. 860 * 861 * @param bytes The buffer which contains the data 862 * @param index Current position in the buffer 863 * @return <code>true</code> if the current character is a the underscore 864 */ 865 public static boolean isUnderscore( byte[] bytes, int index ) 866 { 867 if ( ( bytes == null ) || ( bytes.length == 0 ) || ( index < 0 ) || ( index >= bytes.length ) ) 868 { 869 return false; 870 } 871 else 872 { 873 byte c = bytes[index]; 874 875 return c == 0x5F; 876 } 877 } 878 879}