Changeset 12496
- Timestamp:
- 02/21/10 17:29:39 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/abcl/src/org/armedbear/lisp/StringFunctions.java
r12495 r12496 39 39 public final class StringFunctions { 40 40 private final static class StringIndicesAndChars { 41 AbstractString string1; 41 public AbstractString string1; 42 public boolean convertCase = false; 42 43 public char[] array1; 43 44 public char[] array2; … … 80 81 81 82 } 83 84 private final static char upcaseIfNeeded(char c, boolean convert) { 85 return convert ? LispCharacter.toUpperCase(c) : c; 86 } 82 87 83 88 private final static StringIndicesAndChars … … 271 276 return -1; 272 277 } 273 char c1 = indicesAndChars.array1[i]; 274 char c2 = indicesAndChars.array2[j]; 278 char c1 = upcaseIfNeeded(indicesAndChars.array1[i], 279 indicesAndChars.convertCase); 280 char c2 = upcaseIfNeeded(indicesAndChars.array2[j], 281 indicesAndChars.convertCase); 275 282 if (c1 == c2) { 276 283 ++i; … … 350 357 return -1; 351 358 } 352 char c1 = indicesAndChars.array1[i]; 353 char c2 = indicesAndChars.array2[j]; 359 char c1 = upcaseIfNeeded(indicesAndChars.array1[i], 360 indicesAndChars.convertCase); 361 char c2 = upcaseIfNeeded(indicesAndChars.array2[j], 362 indicesAndChars.convertCase); 354 363 if (c1 == c2) { 355 364 ++i; … … 406 415 }; 407 416 408 private static int stringLessp(StringIndicesAndChars indicesAndChars) { 409 int i = indicesAndChars.start1; 410 int j = indicesAndChars.start2; 411 while (true) { 412 if (i == indicesAndChars.end1) { 413 // Reached end of string1. 414 if (j == indicesAndChars.end2) 415 return -1; // Strings are identical. 416 return i; 417 } 418 if (j == indicesAndChars.end2) { 419 // Reached end of string2. 420 return -1; 421 } 422 char c1 = LispCharacter.toUpperCase(indicesAndChars.array1[i]); 423 char c2 = LispCharacter.toUpperCase(indicesAndChars.array2[j]); 424 if (c1 == c2) { 425 ++i; 426 ++j; 427 continue; 428 } 429 if (c1 > c2) 430 return -1; 431 // c1 < c2 432 return i; 433 } 434 } 417 435 418 // ### %string-lessp 436 419 // Case insensitive. … … 448 431 stringIndicesAndChars(string1, string2, 449 432 start1, end1, start2, end2); 450 int retVal = stringLessp(indicesAndChars); 433 indicesAndChars.convertCase = true; 434 int retVal = lessThan(indicesAndChars); 451 435 return (retVal >= 0) ? Fixnum.getInstance(retVal) : NIL; 452 436 } … … 470 454 start2, end2, 471 455 start1, end1); 472 int tmp = stringLessp(indicesAndChars); 456 indicesAndChars.convertCase = true; 457 int tmp = lessThan(indicesAndChars); 473 458 return swapReturnValue(tmp, indicesAndChars); 474 459 } 475 460 }; 476 477 private static int stringNotLessp(StringIndicesAndChars indicesAndChars) {478 int i = indicesAndChars.start1;479 int j = indicesAndChars.start2;480 while (true) {481 if (i == indicesAndChars.end1) {482 // Reached end of string1.483 if (j == indicesAndChars.end2)484 return i; // Strings are identical.485 return -1;486 }487 if (j == indicesAndChars.end2) {488 // Reached end of string2.489 return i;490 }491 char c1 = LispCharacter.toUpperCase(indicesAndChars.array1[i]);492 char c2 = LispCharacter.toUpperCase(indicesAndChars.array2[j]);493 if (c1 == c2) {494 ++i;495 ++j;496 continue;497 }498 if (c1 > c2)499 return i;500 // c1 < c2501 return -1;502 }503 }504 505 461 // ### %string-not-lessp 506 462 // Case insensitive. … … 515 471 LispObject start1, LispObject end1, 516 472 LispObject start2, LispObject end2) { 517 StringIndicesAndChars indicesAndChars = 518 stringIndicesAndChars(string1, string2, 519 start1, end1, start2, end2); 520 int retVal = stringNotLessp(indicesAndChars); 521 return (retVal >= 0) ? Fixnum.getInstance(retVal) : NIL; 473 // note the swap of the strings and lengths here.. 474 StringIndicesAndChars indicesAndChars = 475 stringIndicesAndChars(string2, string1, 476 start2, end2, 477 start1, end1); 478 indicesAndChars.convertCase = true; 479 int tmp = lessThanOrEqual(indicesAndChars); 480 return swapReturnValue(tmp, indicesAndChars); 522 481 } 523 482 }; … … 535 494 LispObject start1, LispObject end1, 536 495 LispObject start2, LispObject end2) { 537 // note the swap of the strings and lengths here..538 StringIndicesAndChars indicesAndChars =539 stringIndicesAndChars(string2, string1,540 start2, end2 ,541 start1, end1);542 int tmp = stringNotLessp(indicesAndChars);543 return swapReturnValue(tmp, indicesAndChars);496 StringIndicesAndChars indicesAndChars = 497 stringIndicesAndChars(string1, string2, 498 start1, end1, 499 start2, end2); 500 indicesAndChars.convertCase = true; 501 int tmp = lessThanOrEqual(indicesAndChars); 502 return (tmp >= 0) ? Fixnum.getInstance(tmp) : NIL; 544 503 } 545 504 };
Note: See TracChangeset
for help on using the changeset viewer.