2221 ' spaces at beginning and end ' trimBlanks |
2221 ' spaces at beginning and end ' trimBlanks |
2222 'no spaces' trimBlanks |
2222 'no spaces' trimBlanks |
2223 " |
2223 " |
2224 ! ! |
2224 ! ! |
2225 |
2225 |
2226 !CharacterArray methodsFor:'Compatibility - ST80'! |
2226 !CharacterArray methodsFor:'Compatibility - Squeak'! |
|
2227 |
|
2228 capitalized |
|
2229 ^ self asUppercaseFirst |
|
2230 |
|
2231 " |
|
2232 'hello' capitalized |
|
2233 " |
|
2234 ! |
|
2235 |
|
2236 displayProgressAt:aPointOrNil from:start to:stop during:aBlock |
|
2237 ProgressIndicator |
|
2238 displayProgress:self |
|
2239 at:aPointOrNil |
|
2240 from:start |
|
2241 to:stop |
|
2242 during:aBlock. |
|
2243 |
|
2244 " |
|
2245 'dobedobedoobedoo' |
|
2246 displayProgressAt:(Screen current center) |
|
2247 from:0 to:100 |
|
2248 during:[:val | |
|
2249 0 to:100 do:[:i | |
|
2250 val value:i. |
|
2251 Delay waitForSeconds:0.05. |
|
2252 ] |
|
2253 ] |
|
2254 " |
|
2255 ! |
|
2256 |
|
2257 endsWithDigit |
|
2258 "Answer whether the receiver's final character represents a digit. 3/11/96 sw" |
|
2259 |
|
2260 ^ self size > 0 and: [self last isDigit] |
|
2261 ! |
|
2262 |
|
2263 findTokens:delimiters |
|
2264 ^ self asCollectionOfSubstringsSeparatedByAny:delimiters |
|
2265 ! |
|
2266 |
|
2267 includesSubString:aString |
|
2268 "return true, if a substring is contained in the receiver. |
|
2269 The compare is case sensitive." |
|
2270 |
|
2271 ^ self includesString:aString |
|
2272 |
|
2273 " |
|
2274 'hello world' includesSubString:'Hel' |
|
2275 'hello world' includesSubString:'hel' |
|
2276 'hello world' includesSubString:'llo' |
|
2277 " |
|
2278 |
|
2279 |
|
2280 |
|
2281 ! |
|
2282 |
|
2283 includesSubstring:aString caseSensitive:caseSensitive |
|
2284 "return true, if a substring is contained in the receiver. |
|
2285 The argument, caseSensitive controls if case is ignored in the compare." |
|
2286 |
|
2287 "/ for now, a q&d hack ... |
|
2288 |
|
2289 caseSensitive ifFalse:[ |
|
2290 ^ self asLowercase includesString:aString asLowercase |
|
2291 ]. |
|
2292 ^ self includesString:aString |
|
2293 |
|
2294 " |
|
2295 'hello world' includesSubstring:'Hel' caseSensitive:true |
|
2296 'hello world' includesSubstring:'Hel' caseSensitive:false |
|
2297 " |
|
2298 |
|
2299 |
|
2300 |
|
2301 ! |
|
2302 |
|
2303 lastSpacePosition |
|
2304 ^ self lastIndexOfSeparator |
|
2305 ! |
|
2306 |
|
2307 truncateTo:smallSize |
|
2308 "return myself or a copy shortened to smallSize. 1/18/96 sw" |
|
2309 |
|
2310 self size <= smallSize ifTrue:[^ self]. |
|
2311 ^ self copyFrom: 1 to: smallSize |
|
2312 |
|
2313 " |
|
2314 'hello world' truncateTo:5 |
|
2315 'hello' truncateTo:10 |
|
2316 |
|
2317 'hello world' copyTo:5 |
|
2318 'hello' copyTo:10 |
|
2319 " |
|
2320 ! |
|
2321 |
|
2322 withBlanksTrimmed |
|
2323 "Return a copy of the receiver from which leading and trailing blanks have been trimmed." |
|
2324 |
|
2325 ^ self withoutSpaces |
|
2326 |
|
2327 " |
|
2328 ' hello world ' withBlanksTrimmed |
|
2329 " |
|
2330 |
|
2331 |
|
2332 |
|
2333 ! |
|
2334 |
|
2335 withNoLineLongerThan: aNumber |
|
2336 "Answer a string with the same content as receiver, but rewrapped so that no line has more characters than the given number" |
|
2337 |
|
2338 | listOfLines currentLast currentStart resultString putativeLast putativeLine crPosition | |
|
2339 |
|
2340 aNumber isNumber not | (aNumber < 1) ifTrue: [self error: 'too narrow']. |
|
2341 listOfLines _ OrderedCollection new. |
|
2342 currentLast _ 0. |
|
2343 [currentLast < self size] whileTrue: |
|
2344 [currentStart _ currentLast + 1. |
|
2345 putativeLast _ (currentStart + aNumber - 1) min: self size. |
|
2346 putativeLine _ self copyFrom: currentStart to: putativeLast. |
|
2347 (crPosition _ putativeLine indexOf: Character cr) > 0 ifTrue: |
|
2348 [putativeLast _ currentStart + crPosition - 1. |
|
2349 putativeLine _ self copyFrom: currentStart to: putativeLast]. |
|
2350 currentLast _ putativeLast == self size |
|
2351 ifTrue: |
|
2352 [putativeLast] |
|
2353 ifFalse: |
|
2354 [currentStart + putativeLine lastSpacePosition - 1]. |
|
2355 currentLast <= currentStart ifTrue: |
|
2356 ["line has NO spaces; baleout!!" |
|
2357 currentLast _ putativeLast]. |
|
2358 listOfLines add: (self copyFrom: currentStart to: currentLast) withBlanksTrimmed]. |
|
2359 |
|
2360 listOfLines size > 0 ifFalse: [^ '']. |
|
2361 resultString _ listOfLines first. |
|
2362 2 to: listOfLines size do: |
|
2363 [:i | resultString _ resultString, Character cr asString, (listOfLines at: i)]. |
|
2364 ^ resultString |
|
2365 |
|
2366 " |
|
2367 #(5 7 20) collect: |
|
2368 [:i | 'Fred the bear went down to the brook to read his book in silence' withNoLineLongerThan: i] |
|
2369 " |
|
2370 |
|
2371 |
|
2372 |
|
2373 ! ! |
|
2374 |
|
2375 !CharacterArray methodsFor:'Compatibility - V''Age'! |
|
2376 |
|
2377 addLineDelimiter |
|
2378 "replace all '\'-characters by line delimiter (cr) - characters. |
|
2379 This has been added for VisualAge compatibility." |
|
2380 |
|
2381 ^ self withCRs |
|
2382 ! |
|
2383 |
|
2384 bindWith:aString |
|
2385 "return a copy of the receiver, where a '%1' escape is |
|
2386 replaced by aString. |
|
2387 This has been added for VisualAge compatibility." |
|
2388 |
|
2389 ^ self expandPlaceholdersWith:(Array with:aString) |
|
2390 |
|
2391 " |
|
2392 'do you like %1 ?' bindWith:'smalltalk' |
|
2393 " |
|
2394 ! |
|
2395 |
|
2396 bindWith:string1 with:string2 |
|
2397 "return a copy of the receiver, where a '%1' escape is |
|
2398 replaced by string1 and '%2' is replaced by string2. |
|
2399 This has been added for VisualAge compatibility." |
|
2400 |
|
2401 ^ self expandPlaceholdersWith:(Array with:string1 with:string2) |
|
2402 |
|
2403 " |
|
2404 'do you prefer %1 or rather %2 ?' |
|
2405 bindWith:'smalltalk' with:'c++' |
|
2406 " |
|
2407 ! |
|
2408 |
|
2409 bindWith:str1 with:str2 with:str3 |
|
2410 "return a copy of the receiver, where a '%1', '%2' and '%3' escapes |
|
2411 are replaced by str1, str2 and str3 respectively. |
|
2412 This has been added for VisualAge compatibility." |
|
2413 |
|
2414 ^ self expandPlaceholdersWith:(Array with:str1 with:str2 with:str3) |
|
2415 |
|
2416 " |
|
2417 'do you prefer %1 or rather %2 (not talking about %3) ?' |
|
2418 bindWith:'smalltalk' with:'c++' with:'c' |
|
2419 " |
|
2420 ! |
|
2421 |
|
2422 bindWith:str1 with:str2 with:str3 with:str4 |
|
2423 "return a copy of the receiver, where a '%1', '%2', '%3' and '%4' escapes |
|
2424 are replaced by str1, str2, str3 and str4 respectively. |
|
2425 This has been added for VisualAge compatibility." |
|
2426 |
|
2427 ^ self expandPlaceholdersWith:(Array with:str1 with:str2 with:str3 with:str4) |
|
2428 |
|
2429 " |
|
2430 'do you prefer %1 or rather %2 (not talking about %3 or even %4) ?' |
|
2431 bindWith:'smalltalk' with:'c++' with:'c' with:'assembler' |
|
2432 " |
|
2433 ! |
|
2434 |
|
2435 bindWith:str1 with:str2 with:str3 with:str4 with:str5 |
|
2436 "return a copy of the receiver, where a '%1' .. '%5' escapes |
|
2437 are replaced by str1 .. str5 respectively. |
|
2438 This has been added for VisualAge compatibility." |
|
2439 |
|
2440 ^ self expandPlaceholdersWith:(Array with:str1 with:str2 with:str3 with:str4 with:str5) |
|
2441 |
|
2442 "Created: 31.1.1997 / 16:25:42 / cg" |
|
2443 ! |
|
2444 |
|
2445 bindWith:str1 with:str2 with:str3 with:str4 with:str5 with:str6 |
|
2446 "return a copy of the receiver, where a '%1' .. '%6' escapes |
|
2447 are replaced by str1 .. str5 respectively. |
|
2448 This has been added for VisualAge compatibility." |
|
2449 |
|
2450 ^ self expandPlaceholdersWith:(Array with:str1 with:str2 |
|
2451 with:str3 with:str4 |
|
2452 with:str5 with:str6) |
|
2453 |
|
2454 ! |
|
2455 |
|
2456 bindWithArguments:anArrayOfStrings |
|
2457 "return a copy of the receiver, where a '%i' escape |
|
2458 is replaced by the coresponding string from the argument array. |
|
2459 'i' may be between 1 and 9 (i.e. a maximum of 9 placeholders is allowed). |
|
2460 This has been added for VisualAge compatibility." |
|
2461 |
|
2462 ^ self expandPlaceholdersWith:anArrayOfStrings |
|
2463 |
|
2464 " |
|
2465 'do you prefer %1 or rather %2 (not talking about %3) ?' |
|
2466 bindWithArguments:#('smalltalk' 'c++' 'c') |
|
2467 " |
|
2468 ! |
|
2469 |
|
2470 subStrings |
|
2471 "return an array consisting of all words contained in the receiver. |
|
2472 Words are separated by whitespace. |
|
2473 This has been added for VisualAge compatibility." |
|
2474 |
|
2475 ^ self asCollectionOfWords |
|
2476 |
|
2477 " |
|
2478 'hello world, this is smalltalk' subStrings |
|
2479 " |
|
2480 ! |
|
2481 |
|
2482 subStrings:separatorCharacter |
|
2483 "return an array consisting of all words contained in the receiver. |
|
2484 Words are separated by separatorCharacter. |
|
2485 This has been added for VisualAge compatibility." |
|
2486 |
|
2487 ^ self asCollectionOfSubstringsSeparatedBy:separatorCharacter |
|
2488 |
|
2489 " |
|
2490 'foo:bar:baz:smalltalk' subStrings:$: |
|
2491 " |
|
2492 ! |
|
2493 |
|
2494 trimSeparators |
|
2495 "return a copy of the receiver without leading and trailing whiteSpace" |
|
2496 |
|
2497 ^ self withoutSeparators |
|
2498 ! ! |
|
2499 |
|
2500 !CharacterArray methodsFor:'Compatibility - VW'! |
2227 |
2501 |
2228 expandMacros |
2502 expandMacros |
2229 "ST80 compatibility - expand '<..>' macros with |
2503 "ST80 compatibility - expand '<..>' macros with |
2230 argument strings. Similar to #bindWith:. |
2504 argument strings. Similar to #bindWith:. |
2231 Read the comment in #expandMacrosWithArguments: about |
2505 Read the comment in #expandMacrosWithArguments: about |
2359 " |
2633 " |
2360 'hello <1p> how are you' expandMacrosWith:(OperatingSystem getLoginName) |
2634 'hello <1p> how are you' expandMacrosWith:(OperatingSystem getLoginName) |
2361 " |
2635 " |
2362 |
2636 |
2363 "Modified: / 18.6.1998 / 16:04:46 / cg" |
2637 "Modified: / 18.6.1998 / 16:04:46 / cg" |
2364 ! ! |
|
2365 |
|
2366 !CharacterArray methodsFor:'Compatibility - Squeak'! |
|
2367 |
|
2368 capitalized |
|
2369 ^ self asUppercaseFirst |
|
2370 |
|
2371 " |
|
2372 'hello' capitalized |
|
2373 " |
|
2374 ! |
|
2375 |
|
2376 displayProgressAt:aPointOrNil from:start to:stop during:aBlock |
|
2377 ProgressIndicator |
|
2378 displayProgress:self |
|
2379 at:aPointOrNil |
|
2380 from:start |
|
2381 to:stop |
|
2382 during:aBlock. |
|
2383 |
|
2384 " |
|
2385 'dobedobedoobedoo' |
|
2386 displayProgressAt:(Screen current center) |
|
2387 from:0 to:100 |
|
2388 during:[:val | |
|
2389 0 to:100 do:[:i | |
|
2390 val value:i. |
|
2391 Delay waitForSeconds:0.05. |
|
2392 ] |
|
2393 ] |
|
2394 " |
|
2395 ! |
|
2396 |
|
2397 endsWithDigit |
|
2398 "Answer whether the receiver's final character represents a digit. 3/11/96 sw" |
|
2399 |
|
2400 ^ self size > 0 and: [self last isDigit] |
|
2401 ! |
|
2402 |
|
2403 findTokens:delimiters |
|
2404 ^ self asCollectionOfSubstringsSeparatedByAny:delimiters |
|
2405 ! |
|
2406 |
|
2407 includesSubString:aString |
|
2408 "return true, if a substring is contained in the receiver. |
|
2409 The compare is case sensitive." |
|
2410 |
|
2411 ^ self includesString:aString |
|
2412 |
|
2413 " |
|
2414 'hello world' includesSubString:'Hel' |
|
2415 'hello world' includesSubString:'hel' |
|
2416 'hello world' includesSubString:'llo' |
|
2417 " |
|
2418 |
|
2419 |
|
2420 |
|
2421 ! |
|
2422 |
|
2423 includesSubstring:aString caseSensitive:caseSensitive |
|
2424 "return true, if a substring is contained in the receiver. |
|
2425 The argument, caseSensitive controls if case is ignored in the compare." |
|
2426 |
|
2427 "/ for now, a q&d hack ... |
|
2428 |
|
2429 caseSensitive ifFalse:[ |
|
2430 ^ self asLowercase includesString:aString asLowercase |
|
2431 ]. |
|
2432 ^ self includesString:aString |
|
2433 |
|
2434 " |
|
2435 'hello world' includesSubstring:'Hel' caseSensitive:true |
|
2436 'hello world' includesSubstring:'Hel' caseSensitive:false |
|
2437 " |
|
2438 |
|
2439 |
|
2440 |
|
2441 ! |
|
2442 |
|
2443 lastSpacePosition |
|
2444 ^ self lastIndexOfSeparator |
|
2445 ! |
|
2446 |
|
2447 truncateTo:smallSize |
|
2448 "return myself or a copy shortened to smallSize. 1/18/96 sw" |
|
2449 |
|
2450 self size <= smallSize ifTrue:[^ self]. |
|
2451 ^ self copyFrom: 1 to: smallSize |
|
2452 |
|
2453 " |
|
2454 'hello world' truncateTo:5 |
|
2455 'hello' truncateTo:10 |
|
2456 |
|
2457 'hello world' copyTo:5 |
|
2458 'hello' copyTo:10 |
|
2459 " |
|
2460 ! |
|
2461 |
|
2462 withBlanksTrimmed |
|
2463 "Return a copy of the receiver from which leading and trailing blanks have been trimmed." |
|
2464 |
|
2465 ^ self withoutSpaces |
|
2466 |
|
2467 " |
|
2468 ' hello world ' withBlanksTrimmed |
|
2469 " |
|
2470 |
|
2471 |
|
2472 |
|
2473 ! |
|
2474 |
|
2475 withNoLineLongerThan: aNumber |
|
2476 "Answer a string with the same content as receiver, but rewrapped so that no line has more characters than the given number" |
|
2477 |
|
2478 | listOfLines currentLast currentStart resultString putativeLast putativeLine crPosition | |
|
2479 |
|
2480 aNumber isNumber not | (aNumber < 1) ifTrue: [self error: 'too narrow']. |
|
2481 listOfLines _ OrderedCollection new. |
|
2482 currentLast _ 0. |
|
2483 [currentLast < self size] whileTrue: |
|
2484 [currentStart _ currentLast + 1. |
|
2485 putativeLast _ (currentStart + aNumber - 1) min: self size. |
|
2486 putativeLine _ self copyFrom: currentStart to: putativeLast. |
|
2487 (crPosition _ putativeLine indexOf: Character cr) > 0 ifTrue: |
|
2488 [putativeLast _ currentStart + crPosition - 1. |
|
2489 putativeLine _ self copyFrom: currentStart to: putativeLast]. |
|
2490 currentLast _ putativeLast == self size |
|
2491 ifTrue: |
|
2492 [putativeLast] |
|
2493 ifFalse: |
|
2494 [currentStart + putativeLine lastSpacePosition - 1]. |
|
2495 currentLast <= currentStart ifTrue: |
|
2496 ["line has NO spaces; baleout!!" |
|
2497 currentLast _ putativeLast]. |
|
2498 listOfLines add: (self copyFrom: currentStart to: currentLast) withBlanksTrimmed]. |
|
2499 |
|
2500 listOfLines size > 0 ifFalse: [^ '']. |
|
2501 resultString _ listOfLines first. |
|
2502 2 to: listOfLines size do: |
|
2503 [:i | resultString _ resultString, Character cr asString, (listOfLines at: i)]. |
|
2504 ^ resultString |
|
2505 |
|
2506 " |
|
2507 #(5 7 20) collect: |
|
2508 [:i | 'Fred the bear went down to the brook to read his book in silence' withNoLineLongerThan: i] |
|
2509 " |
|
2510 |
|
2511 |
|
2512 |
|
2513 ! ! |
|
2514 |
|
2515 !CharacterArray methodsFor:'Compatibility - V''Age'! |
|
2516 |
|
2517 addLineDelimiter |
|
2518 "replace all '\'-characters by line delimiter (cr) - characters. |
|
2519 This has been added for VisualAge compatibility." |
|
2520 |
|
2521 ^ self withCRs |
|
2522 ! |
|
2523 |
|
2524 bindWith:aString |
|
2525 "return a copy of the receiver, where a '%1' escape is |
|
2526 replaced by aString. |
|
2527 This has been added for VisualAge compatibility." |
|
2528 |
|
2529 ^ self expandPlaceholdersWith:(Array with:aString) |
|
2530 |
|
2531 " |
|
2532 'do you like %1 ?' bindWith:'smalltalk' |
|
2533 " |
|
2534 ! |
|
2535 |
|
2536 bindWith:string1 with:string2 |
|
2537 "return a copy of the receiver, where a '%1' escape is |
|
2538 replaced by string1 and '%2' is replaced by string2. |
|
2539 This has been added for VisualAge compatibility." |
|
2540 |
|
2541 ^ self expandPlaceholdersWith:(Array with:string1 with:string2) |
|
2542 |
|
2543 " |
|
2544 'do you prefer %1 or rather %2 ?' |
|
2545 bindWith:'smalltalk' with:'c++' |
|
2546 " |
|
2547 ! |
|
2548 |
|
2549 bindWith:str1 with:str2 with:str3 |
|
2550 "return a copy of the receiver, where a '%1', '%2' and '%3' escapes |
|
2551 are replaced by str1, str2 and str3 respectively. |
|
2552 This has been added for VisualAge compatibility." |
|
2553 |
|
2554 ^ self expandPlaceholdersWith:(Array with:str1 with:str2 with:str3) |
|
2555 |
|
2556 " |
|
2557 'do you prefer %1 or rather %2 (not talking about %3) ?' |
|
2558 bindWith:'smalltalk' with:'c++' with:'c' |
|
2559 " |
|
2560 ! |
|
2561 |
|
2562 bindWith:str1 with:str2 with:str3 with:str4 |
|
2563 "return a copy of the receiver, where a '%1', '%2', '%3' and '%4' escapes |
|
2564 are replaced by str1, str2, str3 and str4 respectively. |
|
2565 This has been added for VisualAge compatibility." |
|
2566 |
|
2567 ^ self expandPlaceholdersWith:(Array with:str1 with:str2 with:str3 with:str4) |
|
2568 |
|
2569 " |
|
2570 'do you prefer %1 or rather %2 (not talking about %3 or even %4) ?' |
|
2571 bindWith:'smalltalk' with:'c++' with:'c' with:'assembler' |
|
2572 " |
|
2573 ! |
|
2574 |
|
2575 bindWith:str1 with:str2 with:str3 with:str4 with:str5 |
|
2576 "return a copy of the receiver, where a '%1' .. '%5' escapes |
|
2577 are replaced by str1 .. str5 respectively. |
|
2578 This has been added for VisualAge compatibility." |
|
2579 |
|
2580 ^ self expandPlaceholdersWith:(Array with:str1 with:str2 with:str3 with:str4 with:str5) |
|
2581 |
|
2582 "Created: 31.1.1997 / 16:25:42 / cg" |
|
2583 ! |
|
2584 |
|
2585 bindWith:str1 with:str2 with:str3 with:str4 with:str5 with:str6 |
|
2586 "return a copy of the receiver, where a '%1' .. '%6' escapes |
|
2587 are replaced by str1 .. str5 respectively. |
|
2588 This has been added for VisualAge compatibility." |
|
2589 |
|
2590 ^ self expandPlaceholdersWith:(Array with:str1 with:str2 |
|
2591 with:str3 with:str4 |
|
2592 with:str5 with:str6) |
|
2593 |
|
2594 ! |
|
2595 |
|
2596 bindWithArguments:anArrayOfStrings |
|
2597 "return a copy of the receiver, where a '%i' escape |
|
2598 is replaced by the coresponding string from the argument array. |
|
2599 'i' may be between 1 and 9 (i.e. a maximum of 9 placeholders is allowed). |
|
2600 This has been added for VisualAge compatibility." |
|
2601 |
|
2602 ^ self expandPlaceholdersWith:anArrayOfStrings |
|
2603 |
|
2604 " |
|
2605 'do you prefer %1 or rather %2 (not talking about %3) ?' |
|
2606 bindWithArguments:#('smalltalk' 'c++' 'c') |
|
2607 " |
|
2608 ! |
|
2609 |
|
2610 subStrings |
|
2611 "return an array consisting of all words contained in the receiver. |
|
2612 Words are separated by whitespace. |
|
2613 This has been added for VisualAge compatibility." |
|
2614 |
|
2615 ^ self asCollectionOfWords |
|
2616 |
|
2617 " |
|
2618 'hello world, this is smalltalk' subStrings |
|
2619 " |
|
2620 ! |
|
2621 |
|
2622 subStrings:separatorCharacter |
|
2623 "return an array consisting of all words contained in the receiver. |
|
2624 Words are separated by separatorCharacter. |
|
2625 This has been added for VisualAge compatibility." |
|
2626 |
|
2627 ^ self asCollectionOfSubstringsSeparatedBy:separatorCharacter |
|
2628 |
|
2629 " |
|
2630 'foo:bar:baz:smalltalk' subStrings:$: |
|
2631 " |
|
2632 ! |
|
2633 |
|
2634 trimSeparators |
|
2635 "return a copy of the receiver without leading and trailing whiteSpace" |
|
2636 |
|
2637 ^ self withoutSeparators |
|
2638 ! ! |
2638 ! ! |
2639 |
2639 |
2640 !CharacterArray methodsFor:'character searching'! |
2640 !CharacterArray methodsFor:'character searching'! |
2641 |
2641 |
2642 includesMatchCharacters |
2642 includesMatchCharacters |