Changeset 12489
- Timestamp:
- 02/20/10 20:17:20 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/abcl/src/org/armedbear/lisp/StringFunctions.java
r12488 r12489 3 3 * 4 4 * Copyright (C) 2003-2005 Peter Graves 5 * Copyright (C) 2010 Ville Voutilainen 5 6 * $Id$ 6 7 * … … 207 208 }; 208 209 209 // ### %string<210 // Case sensitive.211 210 private static int lessThan(StringIndicesAndChars indicesAndChars) { 212 211 int i = indicesAndChars.start1; … … 236 235 } 237 236 } 237 238 // ### %string< 239 // Case sensitive. 238 240 private static final Primitive _STRING_LESS_THAN = new pf__string_less_than(); 239 241 private static final class pf__string_less_than extends Primitive { … … 280 282 } 281 283 }; 284 282 285 private static int lessThanOrEqual(StringIndicesAndChars indicesAndChars) { 283 286 int i = indicesAndChars.start1; … … 353 356 }; 354 357 358 private static int stringLessp(StringIndicesAndChars indicesAndChars) { 359 int i = indicesAndChars.start1; 360 int j = indicesAndChars.start2; 361 while (true) { 362 if (i == indicesAndChars.end1) { 363 // Reached end of string1. 364 if (j == indicesAndChars.end2) 365 return -1; // Strings are identical. 366 return i; 367 } 368 if (j == indicesAndChars.end2) { 369 // Reached end of string2. 370 return -1; 371 } 372 char c1 = LispCharacter.toUpperCase(indicesAndChars.array1[i]); 373 char c2 = LispCharacter.toUpperCase(indicesAndChars.array2[j]); 374 if (c1 == c2) { 375 ++i; 376 ++j; 377 continue; 378 } 379 if (c1 > c2) 380 return -1; 381 // c1 < c2 382 return i; 383 } 384 } 355 385 // ### %string-lessp 356 386 // Case insensitive. … … 362 392 363 393 @Override 364 public LispObject execute(LispObject[] args) { 365 if (args.length != 6) 366 return error(new WrongNumberOfArgumentsException(this)); 367 StringIndicesAndChars indicesAndChars = stringIndicesAndChars(args); 368 int i = indicesAndChars.start1; 369 int j = indicesAndChars.start2; 370 while (true) { 371 if (i == indicesAndChars.end1) { 372 // Reached end of string1. 373 if (j == indicesAndChars.end2) 374 return NIL; // Strings are identical. 375 return Fixnum.getInstance(i); 376 } 377 if (j == indicesAndChars.end2) { 378 // Reached end of string2. 379 return NIL; 380 } 381 char c1 = LispCharacter.toUpperCase(indicesAndChars.array1[i]); 382 char c2 = LispCharacter.toUpperCase(indicesAndChars.array2[j]); 383 if (c1 == c2) { 384 ++i; 385 ++j; 386 continue; 387 } 388 if (c1 > c2) 389 return NIL; 390 // c1 < c2 391 return Fixnum.getInstance(i); 392 } 394 public LispObject execute(LispObject first, LispObject second, 395 LispObject third, LispObject fourth, 396 LispObject fifth, LispObject sixth) { 397 StringIndicesAndChars indicesAndChars = 398 stringIndicesAndChars(first, second, third, 399 fourth, fifth, sixth); 400 int retVal = stringLessp(indicesAndChars); 401 return (retVal >= 0) ? Fixnum.getInstance(retVal) : NIL; 393 402 } 394 403 }; … … 403 412 404 413 @Override 405 public LispObject execute(LispObject[] args) { 406 if (args.length != 6) 407 return error(new WrongNumberOfArgumentsException(this)); 408 StringIndicesAndChars indicesAndChars = stringIndicesAndChars(args); 409 int i = indicesAndChars.start1; 410 int j = indicesAndChars.start2; 411 while (true) { 412 if (i == indicesAndChars.end1) { 413 // Reached end of string1. 414 return NIL; 415 } 416 if (j == indicesAndChars.end2) { 417 // Reached end of string2. 418 return Fixnum.getInstance(i); 419 } 420 char c1 = LispCharacter.toUpperCase(indicesAndChars.array1[i]); 421 char c2 = LispCharacter.toUpperCase(indicesAndChars.array2[j]); 422 if (c1 == c2) { 423 ++i; 424 ++j; 425 continue; 426 } 427 if (c1 < c2) 428 return NIL; 429 // c1 > c2 430 return Fixnum.getInstance(i); 431 } 432 } 433 }; 414 public LispObject execute(LispObject first, LispObject second, 415 LispObject third, LispObject fourth, 416 LispObject fifth, LispObject sixth) { 417 // note the swap of the strings and lengths here.. 418 StringIndicesAndChars indicesAndChars = 419 stringIndicesAndChars(second, first, 420 fifth, sixth, 421 third, fourth); 422 int tmp = stringLessp(indicesAndChars); 423 if (tmp < 0) { 424 return NIL; 425 } 426 int delta = tmp - indicesAndChars.start1; 427 int retVal = indicesAndChars.start2 + delta; 428 return Fixnum.getInstance(retVal); 429 } 430 }; 431 432 private static int stringNotLessp(StringIndicesAndChars indicesAndChars) { 433 int i = indicesAndChars.start1; 434 int j = indicesAndChars.start2; 435 while (true) { 436 if (i == indicesAndChars.end1) { 437 // Reached end of string1. 438 if (j == indicesAndChars.end2) 439 return i; // Strings are identical. 440 return -1; 441 } 442 if (j == indicesAndChars.end2) { 443 // Reached end of string2. 444 return i; 445 } 446 char c1 = LispCharacter.toUpperCase(indicesAndChars.array1[i]); 447 char c2 = LispCharacter.toUpperCase(indicesAndChars.array2[j]); 448 if (c1 == c2) { 449 ++i; 450 ++j; 451 continue; 452 } 453 if (c1 > c2) 454 return i; 455 // c1 < c2 456 return -1; 457 } 458 } 434 459 435 460 // ### %string-not-lessp … … 442 467 443 468 @Override 444 public LispObject execute(LispObject[] args) { 445 if (args.length != 6) 446 return error(new WrongNumberOfArgumentsException(this)); 447 StringIndicesAndChars indicesAndChars = stringIndicesAndChars(args); 448 int i = indicesAndChars.start1; 449 int j = indicesAndChars.start2; 450 while (true) { 451 if (i == indicesAndChars.end1) { 452 // Reached end of string1. 453 if (j == indicesAndChars.end2) 454 return Fixnum.getInstance(i); // Strings are identical. 455 return NIL; 456 } 457 if (j == indicesAndChars.end2) { 458 // Reached end of string2. 459 return Fixnum.getInstance(i); 460 } 461 char c1 = LispCharacter.toUpperCase(indicesAndChars.array1[i]); 462 char c2 = LispCharacter.toUpperCase(indicesAndChars.array2[j]); 463 if (c1 == c2) { 464 ++i; 465 ++j; 466 continue; 467 } 468 if (c1 > c2) 469 return Fixnum.getInstance(i); 470 // c1 < c2 471 return NIL; 472 } 469 public LispObject execute(LispObject first, LispObject second, 470 LispObject third, LispObject fourth, 471 LispObject fifth, LispObject sixth) { 472 StringIndicesAndChars indicesAndChars = 473 stringIndicesAndChars(first, second, third, 474 fourth, fifth, sixth); 475 int retVal = stringNotLessp(indicesAndChars); 476 return (retVal >= 0) ? Fixnum.getInstance(retVal) : NIL; 473 477 } 474 478 }; … … 483 487 484 488 @Override 485 public LispObject execute(LispObject[] args) { 486 if (args.length != 6) 487 return error(new WrongNumberOfArgumentsException(this)); 488 StringIndicesAndChars indicesAndChars = stringIndicesAndChars(args); 489 int i = indicesAndChars.start1; 490 int j = indicesAndChars.start2; 491 while (true) { 492 if (i == indicesAndChars.end1) { 493 // Reached end of string1. 494 return Fixnum.getInstance(i); 495 } 496 if (j == indicesAndChars.end2) { 497 // Reached end of string2. 498 return NIL; 499 } 500 char c1 = LispCharacter.toUpperCase(indicesAndChars.array1[i]); 501 char c2 = LispCharacter.toUpperCase(indicesAndChars.array2[j]); 502 if (c1 == c2) { 503 ++i; 504 ++j; 505 continue; 506 } 507 if (c1 > c2) 508 return NIL; 509 // c1 < c2 510 return Fixnum.getInstance(i); 511 } 489 public LispObject execute(LispObject first, LispObject second, 490 LispObject third, LispObject fourth, 491 LispObject fifth, LispObject sixth) { 492 // note the swap of the strings and lengths here.. 493 StringIndicesAndChars indicesAndChars = 494 stringIndicesAndChars(second, first, 495 fifth, sixth, 496 third, fourth); 497 int tmp = stringNotLessp(indicesAndChars); 498 if (tmp < 0) { 499 return NIL; 500 } 501 int delta = tmp - indicesAndChars.start1; 502 int retVal = indicesAndChars.start2 + delta; 503 return Fixnum.getInstance(retVal); 512 504 } 513 505 };
Note: See TracChangeset
for help on using the changeset viewer.