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