This repository has been archived by the owner on Jun 9, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
wmlsstring.pir
1099 lines (842 loc) · 23.7 KB
/
wmlsstring.pir
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Copyright (C) 2006-2009, Parrot Foundation.
# $Id$
=head1 WMLScript String library
=head2 Description
This library contains a set of string functions. A string is an array of
characters. Each of the characters has an index. The first character in a
string has an index zero (0). The length of the string is the number of
characters in the array.
The user of the String library can specify a special separator by which
elements in a string can be separated. These elements can be accessed
by specifying the separator and the element index. The first element in a
string has an index zero (0). Each occurrence of the separator in the string
separates two elements (no escaping of separators is allowed).
A White space character is one of the following characters:
=over 4
=item * TAB : Horizontal Tabulation
=item * VT : Vertical Tabulation
=item * FF : Form Feed
=item * SP : Space
=item * LF : Line Feed
=item * CR : Carriage Return
=back
See "WMLScript Standard Libraries Specification", section 9 "String".
=head2 Functions
=cut
.HLL 'wmlscript'
.loadlib 'wmls_group'
.loadlib 'wmls_ops'
.sub 'getString'
new $P0, 'Hash'
.const 'Sub' _string_length = '_string_length'
$P0[0] = _string_length
.const 'Sub' _string_isEmpty = '_string_isEmpty'
$P0[1] = _string_isEmpty
.const 'Sub' _string_charAt = '_string_charAt'
$P0[2] = _string_charAt
.const 'Sub' _string_subString = '_string_subString'
$P0[3] = _string_subString
.const 'Sub' _string_find = '_string_find'
$P0[4] = _string_find
.const 'Sub' _string_replace = '_string_replace'
$P0[5] = _string_replace
.const 'Sub' _string_elements = '_string_elements'
$P0[6] = _string_elements
.const 'Sub' _string_elementAt = '_string_elementAt'
$P0[7] = _string_elementAt
.const 'Sub' _string_removeAt = '_string_removeAt'
$P0[8] = _string_removeAt
.const 'Sub' _string_replaceAt = '_string_replaceAt'
$P0[9] = _string_replaceAt
.const 'Sub' _string_insertAt = '_string_insertAt'
$P0[10] = _string_insertAt
.const 'Sub' _string_squeeze = '_string_squeeze'
$P0[11] = _string_squeeze
.const 'Sub' _string_trim = '_string_trim'
$P0[12] = _string_trim
.const 'Sub' _string_compare = '_string_compare'
$P0[13] = _string_compare
.const 'Sub' _string_toString = '_string_toString'
$P0[14] = _string_toString
.const 'Sub' _string_format = '_string_format'
$P0[15] = _string_format
.return ($P0)
.end
=head3 C<length(string)>
=head4 DESCRIPTION
Returns the length (number of characters) of the given string.
=head4 PARAMETERS
string = String
=head4 RETURN VALUE
Integer or invalid.
=cut
.sub '_string_length' :anon
.param pmc str
.local pmc res
$I0 = isa str, 'WmlsInvalid'
if $I0 goto L1
$S1 = str
$I1 = length $S1
box res, $I1
.return (res)
L1:
new res, 'WmlsInvalid'
.return (res)
.end
=head3 C<isEmpty(string)>
=head4 DESCRIPTION
Returns a boolean true if the string length is zero and boolean false
otherwise.
=head4 PARAMETERS
string = String
=head4 RETURN VALUE
Boolean or invalid.
=cut
.sub '_string_isEmpty' :anon
.param pmc str
.local pmc res
$I0 = isa str, 'WmlsInvalid'
if $I0 goto L1
$S1 = str
$I1 = length $S1
new res, 'WmlsBoolean'
set res, 0
if $I1 goto L2
set res, 1
L2:
.return (res)
L1:
new res, 'WmlsInvalid'
.return (res)
.end
=head3 C<charAt(string, index)>
=head4 DESCRIPTION
Returns a new string of length one containing the character at the specified
index of the given string.
If the index is of type floating-point, Float.int() is first used to calculate the
actual integer index.
=head4 PARAMETERS
string = String
index = Number (the index of the character to be returned)
=head4 RETURN VALUE
String or invalid.
=head4 EXCEPTIONS
If index is out of range then an empty string (C<"">) is returned.
=cut
.sub '_string_charAt' :anon
.param pmc str
.param pmc index_
.local pmc res
$I0 = isa str, 'WmlsInvalid'
if $I0 goto L1
$I0 = isa index_, 'WmlsInteger'
if $I0 goto L2
$I0 = isa index_, 'WmlsFloat'
if $I0 goto L2
goto L1
L2:
$S1 = str
$I1 = length $S1
$I2 = index_
if $I2 < 0 goto L3
if $I2 >= $I1 goto L3
$S0 = substr $S1, $I2, 1
box res, $S0
.return (res)
L3:
new res, 'WmlsString'
.return (res)
L1:
new res, 'WmlsInvalid'
.return (res)
.end
=head3 C<subString(string, startIndex, length)>
=head4 DESCRIPTION
Returns a new string that is a substring of the given string. The substring
begins at the specified startIndex and its length (number of characters) is
the given length. If the startIndex is less than 0 then 0 is used for the
startIndex. If the length is larger than the remaining number of characters in
the string, the length is replaced with the number of remaining characters.
If the startIndex or the length is of type floating-point, Float.int() is first used to
calculate the actual integer value.
=head4 PARAMETERS
string = String
startIndex = Number (the beginning index, inclusive)
length = Number (the length of the substring)
=head4 RETURN VALUE
String or invalid.
=head4 EXCEPTIONS
If startIndex is larger than the last index an empty string (C<"">) is returned.
If length <= 0 an empty string (C<"">) is returned.
=cut
.sub '_string_subString' :anon
.param pmc String
.param pmc startIndex
.param pmc Length
.local pmc res
$I0 = isa String, 'WmlsInvalid'
if $I0 goto L1
$I0 = isa startIndex, 'WmlsInteger'
if $I0 goto L2
$I0 = isa startIndex, 'WmlsFloat'
if $I0 goto L2
goto L1
L2:
$I0 = isa Length, 'WmlsInteger'
if $I0 goto L3
$I0 = isa Length, 'WmlsFloat'
if $I0 goto L3
goto L1
L3:
$S1 = String
$I1 = length $S1
$I2 = startIndex
if $I2 >= 0 goto L4
$I2 = 0
L4:
if $I2 >= $I1 goto L5
$I3 = Length
if $I3 <= 0 goto L5
$S0 = substr $S1, $I2, $I3
box res, $S0
.return (res)
L5:
new res, 'WmlsString'
.return (res)
L1:
new res, 'WmlsInvalid'
.return (res)
.end
=head3 C<find(string, subString)>
=head4 DESCRIPTION
Returns the index of the first character in the string that matches the
requested subString. If no match is found integer value -1 is returned.
Two strings are defined to match when they are identical. Characters with
multiple possible representations match only if they have the same
representation in both strings. No case folding is performed.
=head4 PARAMETERS
string = String
subString = String
=head4 RETURN VALUE
Integer or invalid.
=head4 EXCEPTIONS
If subString is an empty string (C<"">), an invalid value is returned.
=cut
.sub '_string_find' :anon
.param pmc String
.param pmc subString
.local pmc res
$I0 = isa String, 'WmlsInvalid'
if $I0 goto L1
$I0 = isa subString, 'WmlsInvalid'
if $I0 goto L1
$S1 = String
$S2 = subString
$I2 = length $S2
if $I2 == 0 goto L1
$I0 = index $S1, $S2
box res, $I0
.return (res)
L1:
new res, 'WmlsInvalid'
.return (res)
.end
=head3 C<replace(string, oldSubString, newSubString)>
=head4 DESCRIPTION
Returns a new string resulting from replacing all occurrences of
oldSubString in this string with newSubString.
Two strings are defined to match when they are identical. Characters with
multiple possible representations match only if they have the same
representation in both strings. No case folding is performed.
=head4 PARAMETERS
string = String
oldSubString = String
newSubString = String
=head4 RETURN VALUE
String or invalid.
=head4 EXCEPTIONS
If oldSubString is an empty string an C<invalid> value is returned.
=cut
.sub '_string_replace' :anon
.param pmc String
.param pmc oldSubString
.param pmc newSubString
.local pmc res
$I0 = isa String, 'WmlsInvalid'
if $I0 goto L1
$I0 = isa oldSubString, 'WmlsInvalid'
if $I0 goto L1
$I0 = isa newSubString, 'WmlsInvalid'
if $I0 goto L1
$S1 = String
$S2 = oldSubString
$I2 = length $S2
if $I2 == 0 goto L1
$S3 = newSubString
$P0 = split $S2, $S1
$S0 = join $S3, $P0
box res, $S0
.return (res)
L1:
new res, 'WmlsInvalid'
.return (res)
.end
=head3 C<elements(string, separator)>
=head4 DESCRIPTION
Returns the number of elements in the given string separated by the given
separator. Empty string ("") is a valid element (thus, this function can never
return a value that is less or equal to zero).
=head4 PARAMETERS
string = String
separator = String (the first character of the string used as separator)
=head4 RETURN VALUE
Integer or invalid.
=head4 EXCEPTIONS
Returns C<invalid> if the separator is an empty string.
=cut
.sub '_string_elements' :anon
.param pmc str
.param pmc separator
.local pmc res
$I0 = isa str, 'WmlsInvalid'
if $I0 goto L1
$I0 = isa separator, 'WmlsInvalid'
if $I0 goto L1
$S1 = str
$S2 = separator
$I2 = length $S2
if $I2 == 0 goto L1
$S2 = substr $S2, 0, 1
$I1 = length $S1
if $I1 != 0 goto L2
box res, 1
.return (res)
L2:
$P0 = split $S2, $S1
$I0 = elements $P0
box res, $I0
.return (res)
L1:
new res, 'WmlsInvalid'
.return (res)
.end
=head3 C<elementAt(string, index, separator)>
=head4 DESCRIPTION
Search string for index'th element, elements being separated by separator
and return the corresponding element. If the index is less than 0 then the first
element is returned. If the index is larger than the number of elements then
the last element is returned. If the string is an empty string then an empty
string is returned.
If the index is of type floating-point, Float.int() is first used to calculate the
actual index value.
=head4 PARAMETERS
string = String
index = Number (the index of the element to be returned)
separator = String (the first character of the string used as separator)
=head4 RETURN VALUE
String or invalid.
=head4 EXCEPTIONS
Returns C<invalid> if the separator is an empty string.
=cut
.sub '_string_elementAt' :anon
.param pmc str
.param pmc index_
.param pmc separator
.local pmc res
$I0 = isa str, 'WmlsInvalid'
if $I0 goto L1
$I0 = isa index_, 'WmlsInteger'
if $I0 goto L2
$I0 = isa index_, 'WmlsFloat'
if $I0 goto L2
goto L1
L2:
$I0 = isa separator, 'WmlsInvalid'
if $I0 goto L1
$S1 = str
$I2 = index_
if $I2 >= 0 goto L3
$I2 = 0
L3:
$S3 = separator
$I3 = length $S3
if $I3 == 0 goto L1
$S3 = substr $S3, 0, 1
$I1 = length $S1
if $I1 != 0 goto L4
new res, 'WmlsString'
.return (res)
L4:
$P0 = split $S3, $S1
$I0 = elements $P0
if $I2 < $I0 goto L5
$I2 = $I0 - 1
L5:
$S0 = $P0[$I2]
box res, $S0
.return (res)
L1:
new res, 'WmlsInvalid'
.return (res)
.end
=head3 C<removeAt(string, index, separator)>
=head4 DESCRIPTION
Returns a new string where the element and the corresponding separator (if
existing) with the given index are removed from the given string. If the index
is less than 0 then the first element is removed. If the index is larger than the
number of elements then the last element is removed. If the string is empty,
the function returns a new empty string.
If the index is of type floating-point, Float.int() is first used to calculate the
actual index value.
=head4 PARAMETERS
string = String
index = Number (the index of the element to be deleted)
separator = String (the first character of the string used as separator)
=head4 RETURN VALUE
String or invalid.
=head4 EXCEPTIONS
Returns C<invalid> if the separator is an empty string.
=cut
.sub '_string_removeAt' :anon
.param pmc str
.param pmc index_
.param pmc separator
.local pmc res
$I0 = isa str, 'WmlsInvalid'
if $I0 goto L1
$I0 = isa index_, 'WmlsInteger'
if $I0 goto L2
$I0 = isa index_, 'WmlsFloat'
if $I0 goto L2
goto L1
L2:
$I0 = isa separator, 'WmlsInvalid'
if $I0 goto L1
$S1 = str
$I2 = index_
if $I2 >= 0 goto L3
$I2 = 0
L3:
$S3 = separator
$I3 = length $S3
if $I3 == 0 goto L1
$S3 = substr $S3, 0, 1
$I1 = length $S1
if $I1 != 0 goto L4
new res, 'WmlsString'
.return (res)
L4:
$P0 = split $S3, $S1
$I4 = elements $P0
if $I2 < $I4 goto L5
$I2 = $I4 - 1
L5:
dec $I4
new $P1, 'FixedPMCArray'
set $P1, $I4
$I0 = 0
$I1 = 0
L6:
unless $I1 < $I4 goto L7
$S0 = $P0[$I0]
$P1[$I1] = $S0
if $I0 == $I2 goto L8
inc $I1
L8:
inc $I0
goto L6
L7:
$S0 = join $S3, $P1
box res, $S0
.return (res)
L1:
new res, 'WmlsInvalid'
.return (res)
.end
=head3 C<replaceAt(string, element, index, separator)>
=head4 DESCRIPTION
Returns a string with the current element at the specified index replaced with
the given element. If the index is less than 0 then the first element is
replaced. If the index is larger than the number of elements then the last
element is replaced. If the string is empty, the function returns a new string
with the given element.
If the index is of type floating-point, Float.int() is first used to calculate the
actual index value.
=head4 PARAMETERS
string = String
element = String
index = Number (the index of the element to be replaced)
separator = String (the first character of the string used as separator)
=head4 RETURN VALUE
String or invalid.
=head4 EXCEPTIONS
Returns C<invalid> if the separator is an empty string.
=cut
.sub '_string_replaceAt' :anon
.param pmc str
.param pmc element
.param pmc index_
.param pmc separator
.local pmc res
$I0 = isa str, 'WmlsInvalid'
if $I0 goto L1
$I0 = isa element, 'WmlsInvalid'
if $I0 goto L1
$I0 = isa index_, 'WmlsInteger'
if $I0 goto L2
$I0 = isa index_, 'WmlsFloat'
if $I0 goto L2
goto L1
L2:
$I0 = isa separator, 'WmlsInvalid'
if $I0 goto L1
$S1 = str
$S2 = element
$I3 = index_
if $I3 >= 0 goto L3
$I3 = 0
L3:
$S4 = separator
$I4 = length $S4
if $I4 == 0 goto L1
$S4 = substr $S4, 0, 1
$I1 = length $S1
if $I1 != 0 goto L4
box res, $S2
.return (res)
L4:
$P0 = split $S4, $S1
$I0 = elements $P0
if $I3 < $I0 goto L5
$I3 = $I0 - 1
L5:
$P0[$I3] = $S2
$S0 = join $S4, $P0
box res, $S0
.return (res)
L1:
new res, 'WmlsInvalid'
.return (res)
.end
=head3 C<insertAt(string, element, index, separator)>
=head4 DESCRIPTION
Returns a string with the element and the corresponding separator (if
needed) inserted at the specified element index of the original string. If the
index is less than 0 then 0 is used as the index. If the index is larger than the
number of elements then the element is appended at the end of the string. If
the string is empty, the function returns a new string with the given element.
If the index is of type floating-point, Float.int() is first used to calculate the
actual index value.
=head4 PARAMETERS
string = String (original string)
element = String (element to be inserted)
index = Number (the index of the element to be added)
separator = String (the first character of the string used as separator)
=head4 RETURN VALUE
String or invalid.
=head4 EXCEPTIONS
Returns C<invalid> if the separator is an empty string.
=cut
.sub '_string_insertAt' :anon
.param pmc str
.param pmc element
.param pmc index_
.param pmc separator
.local pmc res
$I0 = isa str, 'WmlsInvalid'
if $I0 goto L1
$I0 = isa element, 'WmlsInvalid'
if $I0 goto L1
$I0 = isa index_, 'WmlsInteger'
if $I0 goto L2
$I0 = isa index_, 'WmlsFloat'
if $I0 goto L2
goto L1
L2:
$I0 = isa separator, 'WmlsInvalid'
if $I0 goto L1
$S1 = str
$S2 = element
$I3 = index_
if $I3 >= 0 goto L3
$I3 = 0
L3:
$S4 = separator
$I4 = length $S4
if $I4 == 0 goto L1
$S4 = substr $S4, 0, 1
$I1 = length $S1
if $I1 != 0 goto L4
box res, $S2
.return (res)
L4:
$P0 = split $S4, $S1
$I5 = elements $P0
if $I3 <= $I5 goto L5
$I3 = $I5
L5:
$I6 = $I5 + 1
new $P1, 'FixedPMCArray'
set $P1, $I6
$I0 = 0
$I1 = 0
L6:
unless $I0 < $I5 goto L7
if $I1 != $I3 goto L8
inc $I1
L8:
$S0 = $P0[$I0]
$P1[$I1] = $S0
inc $I0
inc $I1
goto L6
L7:
$P1[$I3] = $S2
$S0 = join $S4, $P1
box res, $S0
.return (res)
L1:
new res, 'WmlsInvalid'
.return (res)
.end
=head3 C<squeeze(string)>
=head4 DESCRIPTION
Returns a string where all consecutive series of white spaces within the
string are reduced to single inter-word space.
=head4 PARAMETERS
String = String
=head4 RETURN VALUE
String or invalid.
=cut
.include 'cclass.pasm'
.sub 'squeeze' :anon
.param string s
.local string res
.local int idx
res = ''
idx = 0
$I1 = length s
L1:
unless idx < $I1 goto L2
$I0 = is_cclass .CCLASS_WHITESPACE, s, idx
if $I0 goto L3
$S0 = substr s, idx, 1
res = concat res, $S0
inc idx
goto L1
L3:
res = concat res, ' '
L4:
inc idx
$I0 = is_cclass .CCLASS_WHITESPACE, s, idx
if $I0 goto L4
goto L1
L2:
.return (res)
.end
.sub '_string_squeeze' :anon
.param pmc str
.local pmc res
$I0 = isa str, 'WmlsInvalid'
if $I0 goto L1
$S1 = str
$S0 = squeeze($S1)
box res, $S0
.return (res)
L1:
new res, 'WmlsInvalid'
.return (res)
.end
=head3 C<trim(string)>
=head4 DESCRIPTION
Returns a string where all trailing and leading white spaces in the given
string have been trimmed.
=head4 PARAMETERS
String = String
=head4 RETURN VALUE
String or invalid.
=cut
.sub 'trim' :anon
.param string s
.local string res
$I1 = 0
L1:
$I0 = is_cclass .CCLASS_WHITESPACE, s, $I1
unless $I0 goto L2
inc $I1
goto L1
L2:
$I2 = length s
L3:
dec $I2
$I0 = is_cclass .CCLASS_WHITESPACE, s, $I2
if $I0 goto L3
inc $I2
$I2 -= $I1
res = substr s, $I1, $I2
.return (res)
.end
.sub '_string_trim' :anon
.param pmc str
.local pmc res
$I0 = isa str, 'WmlsInvalid'
if $I0 goto L1
$S1 = str
$S0 = trim($S1)
box res, $S0
.return (res)
L1:
new res, 'WmlsInvalid'
.return (res)
.end
=head3 C<compare(string1, string2)>
=head4 DESCRIPTION
The return value indicates the lexicographic relation of string1 to string2. The
relation is based on the relation of the character codes in the native
character set. The return value is -1 if string1 is less than string2, 0 if string1
is identical to string2 or 1 if string1 is greater than string2.
=head4 PARAMETERS
String1 = String
String2 = String
=head4 RETURN VALUE
Integer or invalid.
=cut
.sub '_string_compare' :anon
.param pmc string1
.param pmc string2
.local pmc res
$I0 = isa string1, 'WmlsInvalid'
if $I0 goto L1
$I0 = isa string2, 'WmlsInvalid'
if $I0 goto L1
$S1 = string1
$S2 = string2
if $S1 >= $S2 goto L2
box res, -1
.return (res)
L2:
if $S1 > $S2 goto L3
box res, 0
.return (res)
L3:
box res, 1
.return (res)
L1:
new res, 'WmlsInvalid'
.return (res)
.end
=head3 C<toString(value)>
=head4 DESCRIPTION
Returns a string representation of the given value. This function performs
exactly the same conversions as supported by the [WMLScript] language
(automatic conversion from boolean, integer and floating-point values to
strings) except that C<invalid> value returns the string C<"invalid">.
=head4 PARAMETERS
value = Any
=head4 RETURN VALUE
String.
=cut
.sub '_string_toString' :anon
.param pmc value
$S1 = value
.local pmc res
box res, $S1
.return (res)
.end
=head3 C<format(format, value)>
=head4 DESCRIPTION
Converts the given value to a string by using the given formatting provided as
a format string. The format string can contain only one format specifier,
which can be located anywhere inside the string. If more than one is
specified, only the first one (leftmost) is used and the remaining specifiers
are replaced by an empty string. The format specifier has the following form:
% [width] [.precision] type
The C<width> argument is a nonnegative decimal integer controlling the
minimum number of characters printed. If the number of characters in the
output value is less than the specified width, blanks are added to the left until
the minimum width is reached. The C<width> argument never causes the
value to be truncated. If the number of characters in the output value is
greater than the specified width or, if width is not given, all characters of the
value are printed (subject to the precision argument).
The C<precision> argument specifies a nonnegative decimal integer,
preceded by a period (.), which can be used to set the precision of the output
value. The interpretation of this value depends on the given C<type>:
=over 4
=item d
Specifies the minimum number of digits to be printed. If the number
of digits in the value is less than precision, the output value is
padded on the left with zeroes. The value is not truncated when the
number of digits exceeds precision. Default precision is 1. If
precision is specified as 0 and the value to be converted is 0, the
result is an empty string.