equal
deleted
inserted
replaced
|
1 "{ Encoding: utf8 }" |
|
2 |
1 " |
3 " |
2 COPYRIGHT (c) 1995 by Claus Gittinger |
4 COPYRIGHT (c) 1995 by Claus Gittinger |
3 All Rights Reserved |
5 All Rights Reserved |
4 |
6 |
5 This software is furnished under a license and may be used |
7 This software is furnished under a license and may be used |
384 |
386 |
385 initForIntegerOrNil |
387 initForIntegerOrNil |
386 "initialize to convert to/from an integer |
388 "initialize to convert to/from an integer |
387 - if the string is empty or invalid, convert to nil" |
389 - if the string is empty or invalid, convert to nil" |
388 |
390 |
389 valueToStringBlock := [:num | |
391 valueToStringBlock := |
390 num isNil ifTrue:[''] |
392 [:num | |
391 ifFalse:[num printString]]. |
393 num isNil |
392 stringToValueBlock := [:string | |
394 ifTrue:[''] |
393 Integer readFromString:string onError:nil] |
395 ifFalse:[num printString] |
|
396 ]. |
|
397 stringToValueBlock := |
|
398 [:string | |
|
399 Integer readFromString:string onError:nil |
|
400 ] |
394 ! |
401 ! |
395 |
402 |
396 initForNumber |
403 initForNumber |
397 "initialize to convert to/from a number |
404 "initialize to convert to/from a number |
398 - if the string is empty or invalid, convert to 0" |
405 - if the string is empty or invalid, convert to 0" |
403 |
410 |
404 initForNumberOrNil |
411 initForNumberOrNil |
405 "initialize to convert to/from a number |
412 "initialize to convert to/from a number |
406 - if the string is empty or invalid, convert to nil" |
413 - if the string is empty or invalid, convert to nil" |
407 |
414 |
408 valueToStringBlock := [:num | |
415 valueToStringBlock := |
409 num isNil ifTrue:[''] |
416 [:num | |
410 ifFalse:[num printString]]. |
417 num isNil |
411 stringToValueBlock := [:string | |
418 ifTrue:[''] |
412 |s| |
419 ifFalse:[num printString] |
413 |
|
414 s := string. |
|
415 (s endsWith:'.') ifTrue:[ |
|
416 s := s , '0' |
|
417 ]. |
420 ]. |
418 Number readFromString:s onError:nil |
421 stringToValueBlock := |
419 ] |
422 [:string | |
420 |
423 |s| |
421 |
424 |
422 |
425 s := string. |
423 |
426 (s endsWith:'.') ifTrue:[ |
|
427 s := s , '0' |
|
428 ]. |
|
429 Number readFromString:s onError:nil |
|
430 ] |
424 ! |
431 ! |
425 |
432 |
426 initForString |
433 initForString |
427 "initialize for a string - this is trivial" |
434 "initialize for a string - this is trivial" |
428 |
435 |
450 "initialize to convert a 'yes'/'no' string to/from a boolean |
457 "initialize to convert a 'yes'/'no' string to/from a boolean |
451 The string is supposed to be in the current Language |
458 The string is supposed to be in the current Language |
452 (i.e. if german, ja/nein has to be entered. |
459 (i.e. if german, ja/nein has to be entered. |
453 Invalid entries are converted to false." |
460 Invalid entries are converted to false." |
454 |
461 |
455 valueToStringBlock := [:bool | bool ifTrue:[ApplicationModel classResources string:'yes'] |
462 valueToStringBlock := |
456 ifFalse:[ApplicationModel classResources string:'no']]. |
463 [:bool | |
457 stringToValueBlock := [:string | string = (ApplicationModel classResources string:'yes')] |
464 ApplicationModel classResources string:(bool ifTrue:['yes'] ifFalse:['no']) |
|
465 ]. |
|
466 stringToValueBlock := |
|
467 [:string | |
|
468 string = (ApplicationModel classResources string:'yes') |
|
469 ] |
458 ! |
470 ! |
459 |
471 |
460 toPrint:printBlock toRead:readBlock |
472 toPrint:printBlock toRead:readBlock |
461 "initialize to convert using two custom blocks. |
473 "initialize to convert using two custom blocks. |
462 printBlock is supposed to get the objects value as argument, |
474 printBlock is supposed to get the objects value as argument, |