Changeset 4271
- Timestamp:
- 10/10/03 00:49:55 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/j/src/org/armedbear/lisp/StringFunctions.java
r4270 r4271 3 3 * 4 4 * Copyright (C) 2003 Peter Graves 5 * $Id: StringFunctions.java,v 1.1 0 2003-10-09 18:00:30piso Exp $5 * $Id: StringFunctions.java,v 1.11 2003-10-10 00:49:55 piso Exp $ 6 6 * 7 7 * This program is free software; you can redistribute it and/or … … 27 27 // Case sensitive. 28 28 private static final Primitive _STRING_EQUAL = 29 new Primitive("%string=", PACKAGE_SYS, true) { 29 new Primitive("%string=", PACKAGE_SYS, true) 30 { 30 31 public LispObject execute(LispObject[] args) throws ConditionThrowable 31 32 { … … 56 57 // Case sensitive. 57 58 private static final Primitive _STRING_NOT_EQUAL = 58 new Primitive("%string/=", PACKAGE_SYS, true) { 59 public LispObject execute(LispObject[] args) throws ConditionThrowable 60 { 61 if (args.length != 6) 62 throw new ConditionThrowable(new WrongNumberOfArgumentsException(this)); 63 char[] array1 = string(args[0]).chars(); 64 char[] array2 = string(args[1]).chars(); 65 int start1 = Fixnum.getInt(args[2]); 66 int end1 = Fixnum.getInt(args[3]); 67 int start2 = Fixnum.getInt(args[4]); 68 int end2 = Fixnum.getInt(args[5]); 69 int i, j; 70 for (i = start1, j = start2; i < end1 && j < end2; i++, j++) { 59 new Primitive("%string/=", PACKAGE_SYS, true) 60 { 61 public LispObject execute(LispObject[] args) throws ConditionThrowable 62 { 63 if (args.length != 6) 64 throw new ConditionThrowable(new WrongNumberOfArgumentsException(this)); 65 char[] array1 = string(args[0]).chars(); 66 char[] array2 = string(args[1]).chars(); 67 int start1 = Fixnum.getInt(args[2]); 68 int end1 = Fixnum.getInt(args[3]); 69 int start2 = Fixnum.getInt(args[4]); 70 int end2 = Fixnum.getInt(args[5]); 71 int i = start1; 72 int j = start2; 73 while (true) { 74 if (i == end1) { 75 // Reached end of string1. 76 if (j == end2) 77 return NIL; // Strings are identical. 78 return new Fixnum(i); 79 } 80 if (j == end2) { 81 // Reached end of string2 before end of string1. 82 return new Fixnum(i); 83 } 71 84 if (array1[i] != array2[j]) 72 85 return new Fixnum(i); 73 } 74 return NIL; 86 ++i; 87 ++j; 88 } 75 89 } 76 90 }; … … 79 93 // Case insensitive. 80 94 private static final Primitive _STRING_EQUAL_IGNORE_CASE = 81 new Primitive("%string-equal", PACKAGE_SYS, true) { 95 new Primitive("%string-equal", PACKAGE_SYS, true) 96 { 82 97 public LispObject execute(LispObject[] args) throws ConditionThrowable 83 98 { … … 111 126 // Case sensitive. 112 127 private static final Primitive _STRING_NOT_EQUAL_IGNORE_CASE = 113 new Primitive("%string-not-equal", PACKAGE_SYS, true) { 114 public LispObject execute(LispObject[] args) throws ConditionThrowable 115 { 116 if (args.length != 6) 117 throw new ConditionThrowable(new WrongNumberOfArgumentsException(this)); 118 char[] array1 = string(args[0]).chars(); 119 char[] array2 = string(args[1]).chars(); 120 int start1 = Fixnum.getInt(args[2]); 121 int end1 = Fixnum.getInt(args[3]); 122 int start2 = Fixnum.getInt(args[4]); 123 int end2 = Fixnum.getInt(args[5]); 124 int i, j; 125 for (i = start1, j = start2; i < end1 && j < end2; i++, j++) { 128 new Primitive("%string-not-equal", PACKAGE_SYS, true) 129 { 130 public LispObject execute(LispObject[] args) throws ConditionThrowable 131 { 132 if (args.length != 6) 133 throw new ConditionThrowable(new WrongNumberOfArgumentsException(this)); 134 char[] array1 = string(args[0]).chars(); 135 char[] array2 = string(args[1]).chars(); 136 int start1 = Fixnum.getInt(args[2]); 137 int end1 = Fixnum.getInt(args[3]); 138 int start2 = Fixnum.getInt(args[4]); 139 int end2 = Fixnum.getInt(args[5]); 140 int i = start1; 141 int j = start2; 142 while (true) { 143 if (i == end1) { 144 // Reached end of string1. 145 if (j == end2) 146 return NIL; // Strings are identical. 147 return new Fixnum(i); 148 } 149 if (j == end2) { 150 // Reached end of string2. 151 return new Fixnum(i); 152 } 126 153 char c1 = array1[i]; 127 154 char c2 = array2[j]; 128 if (c1 == c2) 129 continue; 130 if (Utilities.toUpperCase(c1) == Utilities.toUpperCase(c2)) 131 continue; 132 if (Utilities.toLowerCase(c1) == Utilities.toLowerCase(c2)) 133 continue; 155 if (c1 == c2 || 156 Utilities.toUpperCase(c1) == Utilities.toUpperCase(c2) || 157 Utilities.toLowerCase(c1) == Utilities.toLowerCase(c2)) 158 { 159 ++i; 160 ++j; 161 continue; 162 } 134 163 return new Fixnum(i); 135 164 } 136 return NIL;137 165 } 138 166 }; … … 141 169 // Case sensitive. 142 170 private static final Primitive _STRING_LESS_THAN = 143 new Primitive("%string<", PACKAGE_SYS, true) { 144 public LispObject execute(LispObject[] args) throws ConditionThrowable 145 { 146 if (args.length != 6) 147 throw new ConditionThrowable(new WrongNumberOfArgumentsException(this)); 148 char[] array1 = string(args[0]).chars(); 149 char[] array2 = string(args[1]).chars(); 150 int start1 = Fixnum.getInt(args[2]); 151 int end1 = Fixnum.getInt(args[3]); 152 int start2 = Fixnum.getInt(args[4]); 153 int end2 = Fixnum.getInt(args[5]); 154 int i, j; 155 for (i = start1, j = start2; i < end1 && j < end2; i++, j++) { 171 new Primitive("%string<", PACKAGE_SYS, true) 172 { 173 public LispObject execute(LispObject[] args) throws ConditionThrowable 174 { 175 if (args.length != 6) 176 throw new ConditionThrowable(new WrongNumberOfArgumentsException(this)); 177 char[] array1 = string(args[0]).chars(); 178 char[] array2 = string(args[1]).chars(); 179 int start1 = Fixnum.getInt(args[2]); 180 int end1 = Fixnum.getInt(args[3]); 181 int start2 = Fixnum.getInt(args[4]); 182 int end2 = Fixnum.getInt(args[5]); 183 int i = start1; 184 int j = start2; 185 while (true) { 186 if (i == end1) { 187 // Reached end of string1. 188 if (j == end2) 189 return NIL; // Strings are identical. 190 return new Fixnum(i); 191 } 192 if (j == end2) { 193 // Reached end of string2. 194 return NIL; 195 } 156 196 char c1 = array1[i]; 157 197 char c2 = array2[j]; 158 if (c1 == c2) 159 continue; 160 if (c1 > c2) 161 return NIL; 198 if (c1 == c2) { 199 ++i; 200 ++j; 201 continue; 202 } 162 203 if (c1 < c2) 163 204 return new Fixnum(i); 164 }165 // Strings are equal.166 return NIL;205 // c1 > c2 206 return NIL; 207 } 167 208 } 168 209 }; … … 171 212 // Case sensitive. 172 213 private static final Primitive _STRING_GREATER_THAN = 173 new Primitive("%string>", PACKAGE_SYS, true) { 174 public LispObject execute(LispObject[] args) throws ConditionThrowable 175 { 176 if (args.length != 6) 177 throw new ConditionThrowable(new WrongNumberOfArgumentsException(this)); 178 char[] array1 = string(args[0]).chars(); 179 char[] array2 = string(args[1]).chars(); 180 int start1 = Fixnum.getInt(args[2]); 181 int end1 = Fixnum.getInt(args[3]); 182 int start2 = Fixnum.getInt(args[4]); 183 int end2 = Fixnum.getInt(args[5]); 184 int i, j; 185 for (i = start1, j = start2; i < end1 && j < end2; i++, j++) { 214 new Primitive("%string>", PACKAGE_SYS, true) 215 { 216 public LispObject execute(LispObject[] args) throws ConditionThrowable 217 { 218 if (args.length != 6) 219 throw new ConditionThrowable(new WrongNumberOfArgumentsException(this)); 220 char[] array1 = string(args[0]).chars(); 221 char[] array2 = string(args[1]).chars(); 222 int start1 = Fixnum.getInt(args[2]); 223 int end1 = Fixnum.getInt(args[3]); 224 int start2 = Fixnum.getInt(args[4]); 225 int end2 = Fixnum.getInt(args[5]); 226 int i = start1; 227 int j = start2; 228 while (true) { 229 if (i == end1) { 230 // Reached end of string1. 231 return NIL; 232 } 233 if (j == end2) { 234 // Reached end of string2. 235 return new Fixnum(i); 236 } 186 237 char c1 = array1[i]; 187 238 char c2 = array2[j]; 188 if (c1 == c2) 189 continue; 239 if (c1 == c2) { 240 ++i; 241 ++j; 242 continue; 243 } 190 244 if (c1 < c2) 191 245 return NIL; 192 if (c1 > c2) 193 return new Fixnum(i); 194 } 195 // Strings are equal. 196 return NIL; 246 // c1 > c2 247 return new Fixnum(i); 248 } 197 249 } 198 250 }; … … 201 253 // Case sensitive. 202 254 private static final Primitive _STRING_LE = 203 new Primitive("%string<=", PACKAGE_SYS, true) { 204 public LispObject execute(LispObject[] args) throws ConditionThrowable 205 { 206 if (args.length != 6) 207 throw new ConditionThrowable(new WrongNumberOfArgumentsException(this)); 208 char[] array1 = string(args[0]).chars(); 209 char[] array2 = string(args[1]).chars(); 210 int start1 = Fixnum.getInt(args[2]); 211 int end1 = Fixnum.getInt(args[3]); 212 int start2 = Fixnum.getInt(args[4]); 213 int end2 = Fixnum.getInt(args[5]); 214 int i, j; 215 for (i = start1, j = start2; i < end1 && j < end2; i++, j++) { 255 new Primitive("%string<=", PACKAGE_SYS, true) 256 { 257 public LispObject execute(LispObject[] args) throws ConditionThrowable 258 { 259 if (args.length != 6) 260 throw new ConditionThrowable(new WrongNumberOfArgumentsException(this)); 261 char[] array1 = string(args[0]).chars(); 262 char[] array2 = string(args[1]).chars(); 263 int start1 = Fixnum.getInt(args[2]); 264 int end1 = Fixnum.getInt(args[3]); 265 int start2 = Fixnum.getInt(args[4]); 266 int end2 = Fixnum.getInt(args[5]); 267 int i = start1; 268 int j = start2; 269 while (true) { 270 if (i == end1) { 271 // Reached end of string1. 272 return new Fixnum(i); 273 } 274 if (j == end2) { 275 // Reached end of string2. 276 return NIL; 277 } 216 278 char c1 = array1[i]; 217 279 char c2 = array2[j]; 218 if (c1 == c2) 219 continue; 280 if (c1 == c2) { 281 ++i; 282 ++j; 283 continue; 284 } 220 285 if (c1 > c2) 221 286 return NIL; 222 if (c1 < c2) 223 return new Fixnum(i); 224 } 225 return new Fixnum(i); 287 // c1 < c2 288 return new Fixnum(i); 289 } 226 290 } 227 291 }; … … 230 294 // Case sensitive. 231 295 private static final Primitive _STRING_GE = 232 new Primitive("%string>=", PACKAGE_SYS, true) { 233 public LispObject execute(LispObject[] args) throws ConditionThrowable 234 { 235 if (args.length != 6) 236 throw new ConditionThrowable(new WrongNumberOfArgumentsException(this)); 237 char[] array1 = string(args[0]).chars(); 238 char[] array2 = string(args[1]).chars(); 239 int start1 = Fixnum.getInt(args[2]); 240 int end1 = Fixnum.getInt(args[3]); 241 int start2 = Fixnum.getInt(args[4]); 242 int end2 = Fixnum.getInt(args[5]); 243 int i, j; 244 for (i = start1, j = start2; i < end1 && j < end2; i++, j++) { 296 new Primitive("%string>=", PACKAGE_SYS, true) 297 { 298 public LispObject execute(LispObject[] args) throws ConditionThrowable 299 { 300 if (args.length != 6) 301 throw new ConditionThrowable(new WrongNumberOfArgumentsException(this)); 302 char[] array1 = string(args[0]).chars(); 303 char[] array2 = string(args[1]).chars(); 304 int start1 = Fixnum.getInt(args[2]); 305 int end1 = Fixnum.getInt(args[3]); 306 int start2 = Fixnum.getInt(args[4]); 307 int end2 = Fixnum.getInt(args[5]); 308 int i = start1; 309 int j = start2; 310 while (true) { 311 if (i == end1) { 312 // Reached end of string1. 313 if (j == end2) 314 return new Fixnum(i); // Strings are identical. 315 return NIL; 316 } 317 if (j == end2) { 318 // Reached end of string2. 319 return new Fixnum(i); 320 } 245 321 char c1 = array1[i]; 246 322 char c2 = array2[j]; 247 if (c1 == c2) 248 continue; 323 if (c1 == c2) { 324 ++i; 325 ++j; 326 continue; 327 } 249 328 if (c1 < c2) 250 329 return NIL; 251 if (c1 > c2) 252 return new Fixnum(i); 253 } 254 return new Fixnum(i); 255 // return LispString.equals(string(args[0]), string(args[1]), 256 // start1, end1, start2, end2); 330 // c1 > c2 331 return new Fixnum(i); 332 } 257 333 } 258 334 }; … … 261 337 // Case insensitive. 262 338 private static final Primitive _STRING_LESSP = 263 new Primitive("%string-lessp", PACKAGE_SYS, true) { 339 new Primitive("%string-lessp", PACKAGE_SYS, true) 340 { 264 341 public LispObject execute(LispObject[] args) throws ConditionThrowable 265 342 { … … 294 371 if (c1 > c2) 295 372 return NIL; 296 if (c1 < c2)297 373 // c1 < c2 374 return new Fixnum(i); 298 375 } 299 376 } … … 303 380 // Case insensitive. 304 381 private static final Primitive _STRING_GREATERP = 305 new Primitive("%string-greaterp", PACKAGE_SYS, true) { 382 new Primitive("%string-greaterp", PACKAGE_SYS, true) 383 { 306 384 public LispObject execute(LispObject[] args) throws ConditionThrowable 307 385 { … … 334 412 if (c1 < c2) 335 413 return NIL; 336 if (c1 > c2)337 414 // c1 > c2 415 return new Fixnum(i); 338 416 } 339 417 } … … 343 421 // Case insensitive. 344 422 private static final Primitive _STRING_NOT_LESSP = 345 new Primitive("%string-not-lessp", PACKAGE_SYS, true) { 423 new Primitive("%string-not-lessp", PACKAGE_SYS, true) 424 { 346 425 public LispObject execute(LispObject[] args) throws ConditionThrowable 347 426 { … … 376 455 if (c1 > c2) 377 456 return new Fixnum(i); 378 if (c1 < c2)379 457 // c1 < c2 458 return NIL; 380 459 } 381 460 } … … 385 464 // Case insensitive. 386 465 private static final Primitive _STRING_NOT_GREATERP = 387 new Primitive("%string-not-greaterp", PACKAGE_SYS, true) { 466 new Primitive("%string-not-greaterp", PACKAGE_SYS, true) 467 { 388 468 public LispObject execute(LispObject[] args) throws ConditionThrowable 389 469 { … … 416 496 if (c1 > c2) 417 497 return NIL; 418 if (c1 < c2)419 498 // c1 < c2 499 return new Fixnum(i); 420 500 } 421 501 } … … 424 504 // ### %string-upcase 425 505 private static final Primitive3 _STRING_UPCASE = 426 new Primitive3("%string-upcase", PACKAGE_SYS, true) { 506 new Primitive3("%string-upcase", PACKAGE_SYS, true) 507 { 427 508 public LispObject execute(LispObject first, LispObject second, 428 509 LispObject third) throws ConditionThrowable … … 457 538 // ### %string-downcase 458 539 private static final Primitive3 _STRING_DOWNCASE = 459 new Primitive3("%string-downcase", PACKAGE_SYS, true) { 540 new Primitive3("%string-downcase", PACKAGE_SYS, true) 541 { 460 542 public LispObject execute(LispObject first, LispObject second, 461 543 LispObject third) throws ConditionThrowable … … 490 572 // ### %string-capitalize 491 573 private static final Primitive3 _STRING_CAPITALIZE= 492 new Primitive3("%string-capitalize", PACKAGE_SYS, true) { 574 new Primitive3("%string-capitalize", PACKAGE_SYS, true) 575 { 493 576 public LispObject execute(LispObject first, LispObject second, 494 577 LispObject third) throws ConditionThrowable … … 535 618 // ### %nstring-upcase 536 619 private static final Primitive3 _NSTRING_UPCASE = 537 new Primitive3("%nstring-upcase", PACKAGE_SYS, true) { 620 new Primitive3("%nstring-upcase", PACKAGE_SYS, true) 621 { 538 622 public LispObject execute(LispObject first, LispObject second, 539 623 LispObject third) throws ConditionThrowable … … 562 646 // ### %nstring-downcase 563 647 private static final Primitive3 _NSTRING_DOWNCASE = 564 new Primitive3("%nstring-downcase", PACKAGE_SYS, true) { 648 new Primitive3("%nstring-downcase", PACKAGE_SYS, true) 649 { 565 650 public LispObject execute(LispObject first, LispObject second, 566 651 LispObject third) throws ConditionThrowable … … 589 674 // ### %nstring-capitalize 590 675 private static final Primitive3 _NSTRING_CAPITALIZE = 591 new Primitive3("%nstring-capitalize", PACKAGE_SYS, true) { 676 new Primitive3("%nstring-capitalize", PACKAGE_SYS, true) 677 { 592 678 public LispObject execute(LispObject first, LispObject second, 593 679 LispObject third) throws ConditionThrowable
Note: See TracChangeset
for help on using the changeset viewer.