[r8242]: main / trunk / interpreter / classes / StringClass.cpp Maximize Restore History

Download this file

StringClass.cpp    2153 lines (1936 with data), 95.3 kB

   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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
/*----------------------------------------------------------------------------*/
/* */
/* Copyright (c) 1995, 2004 IBM Corporation. All rights reserved. */
/* Copyright (c) 2005-2009 Rexx Language Association. All rights reserved. */
/* */
/* This program and the accompanying materials are made available under */
/* the terms of the Common Public License v1.0 which accompanies this */
/* distribution. A copy is also available at the following address: */
/* http://www.oorexx.org/license.html */
/* */
/* Redistribution and use in source and binary forms, with or */
/* without modification, are permitted provided that the following */
/* conditions are met: */
/* */
/* Redistributions of source code must retain the above copyright */
/* notice, this list of conditions and the following disclaimer. */
/* Redistributions in binary form must reproduce the above copyright */
/* notice, this list of conditions and the following disclaimer in */
/* the documentation and/or other materials provided with the distribution. */
/* */
/* Neither the name of Rexx Language Association nor the names */
/* of its contributors may be used to endorse or promote products */
/* derived from this software without specific prior written permission. */
/* */
/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS */
/* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT */
/* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS */
/* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT */
/* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED */
/* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, */
/* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY */
/* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */
/* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
/* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
/* */
/*----------------------------------------------------------------------------*/
/******************************************************************************/
/* REXX Kernel StringClass.c */
/* */
/* Primitive String Class */
/* */
/******************************************************************************/
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits>
#include "RexxCore.h"
#include "StringClass.hpp"
#include "DirectoryClass.hpp"
#include "RexxActivation.hpp"
#include "RexxActivity.hpp"
#include "ProtectedObject.hpp"
#include "StringUtil.hpp"
#include "RexxCompoundTail.hpp"
#include "SystemInterpreter.hpp"
// singleton class instance
RexxClass *RexxString::classInstance = OREF_NULL;
/**
* Create initial class object at bootstrap time.
*/
void RexxString::createInstance()
{
CLASS_CREATE(String, "String", RexxClass);
}
HashCode RexxString::hash()
/******************************************************************************/
/* Function: retrieve the hash value of a string object */
/******************************************************************************/
{
if (!isString(this)) /* a nonprimitive object? */
{
/* see if == overridden. */
return this->sendMessage(OREF_STRICT_EQUAL)->requestString()->getStringHash();
}
else
{
return this->getHashValue(); /* return the string hash */
}
}
/**
* Get the primitive hash value of this String object.
*
* @return The calculated string hash for the string.
*/
HashCode RexxString::getHashValue()
{
// this will calculate the hash if it hasn't been done yet
return getStringHash();
}
/**
* Convert a string returned from an object HashCode() method into
* a binary hashcode suitable for the hash collections.
*
* @return A binary hash code from a string value.
*/
HashCode RexxString::getObjectHashCode()
{
HashCode h;
// ok, we need to pick this string apart and turn this into a numeric code
// a null string is simple.
if (getLength() == 0)
{
h = 1;
}
// if we have at least 4 characters, use them as binary, since that's
// what is normally returned here.
else if (getLength() >= sizeof(HashCode))
{
h = *((HashCode *)getStringData());
}
else
{
// either 1 or 2 characters. Just pick up a short value, which will
// also pick up terminating null if only a single character
h = *((short *)getStringData());
}
return h;
}
void RexxString::live(size_t liveMark)
/******************************************************************************/
/* Function: Normal garbage collection live marking */
/******************************************************************************/
{
memory_mark(this->NumberString);
memory_mark(this->objectVariables);
}
void RexxString::liveGeneral(int reason)
/******************************************************************************/
/* Function: Generalized object marking */
/******************************************************************************/
{
memory_mark_general(this->NumberString);
memory_mark_general(this->objectVariables);
}
void RexxString::flatten(RexxEnvelope *envelope)
/******************************************************************************/
/* Function: Flatten an object */
/******************************************************************************/
{
setUpFlatten(RexxString)
flatten_reference(newThis->NumberString, envelope);
flatten_reference(newThis->objectVariables, envelope);
cleanUpFlatten
}
RexxObject *RexxString::unflatten(RexxEnvelope *envelope)
/******************************************************************************/
/* Function: unflatten an object */
/******************************************************************************/
{
if (this->isProxyObject())
{ /* is this a proxy object? */
// just perform an environment lookup
return TheEnvironment->entry(this);
}
else
{
// perform a normal default unflatten op.
return this->RexxObject::unflatten(envelope);
}
}
RexxString *RexxString::stringValue()
/******************************************************************************/
/* Function: Return the primitive string value of this object */
/******************************************************************************/
{
if (isOfClass(String, this)) /* already a primitive string? */
{
return this; /* just return our selves */
}
else /* need to build a new string */
{
return new_string(this->getStringData(), this->getLength());
}
}
RexxString *RexxString::makeString()
/******************************************************************************/
/* Function: Handle a REQUEST('STRING') request for a REXX string object */
/******************************************************************************/
{
if (this->isBaseClass()) /* really a primitive string? */
{
return this; /* this is easy */
}
else /* need to create a new string */
{
return new_string(this->getStringData(), this->getLength());
}
}
/**
* Baseclass optimization for handling request array calls.
*
* @return The string object converted to an array using default arguments.
*/
RexxArray *RexxString::makeArray()
{
// forward to the Rexx version with default arguments
return this->makeArrayRexx(OREF_NULL);
}
void RexxString::copyIntoTail(RexxCompoundTail *tail)
/******************************************************************************/
/* Function: Handle a tail construction request for an internal object */
/******************************************************************************/
{
/* copy this directly into the tail */
tail->append(this->getStringData(), this->getLength());
}
RexxString *RexxString::primitiveMakeString()
/******************************************************************************/
/* Function: Handle a REQUEST('STRING') request for a REXX string object */
/******************************************************************************/
{
return this; /* this is easy */
}
bool RexxString::numberValue(wholenumber_t &result, stringsize_t digits)
/******************************************************************************/
/* Function: Convert a string object to a long value. Returns false */
/* it will not convert. */
/******************************************************************************/
{
if (!(isString(this))) /* subclassed string object? */
{
return this->requestString()->numberValue(result, digits);
}
/* get the string value's long value */
RexxNumberString *numberstring = this->fastNumberString();
if (numberstring != OREF_NULL ) /* convert ok? */
{
/* convert to integer with proper */
/* precision */
return numberstring->numberValue(result, digits);
}
return false; /* return the "not value long" value */
}
bool RexxString::numberValue(wholenumber_t &result)
/******************************************************************************/
/* Function: Convert a string object to a long value. Returns false */
/* it will not convert. */
/******************************************************************************/
{
if (!(isString(this))) /* subclassed string object? */
{
return this->requestString()->numberValue(result);
}
/* get the string value's long value */
RexxNumberString *numberstring = this->fastNumberString();
if (numberstring != OREF_NULL ) /* convert ok? */
{
/* convert to integer with proper */
/* precision */
return numberstring->numberValue(result);
}
return false; /* return the "not value long" value */
}
bool RexxString::unsignedNumberValue(stringsize_t &result, stringsize_t digits)
/******************************************************************************/
/* Function: Convert a string object to a long value. Returns false */
/* it will not convert. */
/******************************************************************************/
{
if (!(isString(this))) /* subclassed string object? */
{
return this->requestString()->unsignedNumberValue(result, digits);
}
/* get the string value's long value */
RexxNumberString *numberstring = this->fastNumberString();
if (numberstring != OREF_NULL ) /* convert ok? */
{
/* convert to integer with proper */
/* precision */
return numberstring->unsignedNumberValue(result, digits);
}
return false; /* return the "not value long" value */
}
bool RexxString::unsignedNumberValue(stringsize_t &result)
/******************************************************************************/
/* Function: Convert a string object to a long value. Returns false */
/* it will not convert. */
/******************************************************************************/
{
if (!(isString(this))) /* subclassed string object? */
{
return this->requestString()->unsignedNumberValue(result);
}
/* get the string value's long value */
RexxNumberString *numberstring = this->fastNumberString();
if (numberstring != OREF_NULL ) /* convert ok? */
{
/* convert to integer with proper */
/* precision */
return numberstring->unsignedNumberValue(result);
}
return false; /* return the "not value long" value */
}
bool RexxString::doubleValue(double &result)
/******************************************************************************/
/* Function: Convert a string object to a double value */
/******************************************************************************/
{
RexxNumberString *numberDouble = this->fastNumberString(); /* convert String to Numberstring */
if (numberDouble != OREF_NULL) /* Did we get a numberstring? */
{
return numberDouble->doubleValue(result);/* Yup, convert it to double */
}
// non numeric, so this could be one of the special cases
if (strCompare("nan"))
{
result = std::numeric_limits<double>::signaling_NaN();
// this will be false if this is really a NaN value. If true,
// then fall back and use the quiet version.
if (!isnan(result))
{
result = std::numeric_limits<double>::quiet_NaN();
}
return true;
}
if (strCompare("+infinity"))
{
result = +HUGE_VAL;
return true;
}
if (strCompare("-infinity"))
{
result = -HUGE_VAL;
return true;
}
return false; /* not number string, so NODOUBLE */
}
RexxNumberString *RexxString::numberString()
/******************************************************************************/
/* Function: Convert a String Object into a Number Object */
/******************************************************************************/
{
RexxString *newSelf; /* converted string value */
if (this->nonNumeric()) /* Did we already try and convert to */
{
/* to a numberstring and fail? */
return OREF_NULL; /* Yes, no need to try agian. */
}
if (this->NumberString != OREF_NULL) /* see if we have already converted */
{
return this->NumberString; /* return the numberString Object. */
}
if (!isOfClass(String, this))
{ /* not truly a string type? */
newSelf = this->requestString(); /* do the conversion */
/* get a new numberstring Obj */
OrefSet(newSelf, newSelf->NumberString, (RexxNumberString *)new_numberstring(newSelf->getStringData(), newSelf->getLength()));
if (this->NumberString != OREF_NULL) /* Did number convert OK? */
{
newSelf->setHasReferences(); /* Make sure we are sent Live... */
}
}
else
{ /* real primitive string */
/* get a new numberstring Obj */
OrefSet(this, this->NumberString, (RexxNumberString *)new_numberstring(this->getStringData(), this->getLength()));
if (this->NumberString == OREF_NULL) /* Did number convert OK? */
{
this->setNonNumeric(); /* mark as a nonnumeric */
}
else
{
this->setHasReferences(); /* Make sure we are sent Live... */
/* connect the string and number */
this->NumberString->setString(this);
}
}
return this->NumberString; /* return the numberString Object. */
}
RexxNumberString *RexxString::createNumberString()
/******************************************************************************/
/* Function: Convert a String Object into a Number Object */
/******************************************************************************/
{
RexxString *newSelf; /* converted string value */
if (!isOfClass(String, this))
{ /* not truly a string type? */
newSelf = this->requestString(); /* do the conversion */
/* get a new numberstring Obj */
OrefSet(newSelf, newSelf->NumberString, (RexxNumberString *)new_numberstring(newSelf->getStringData(), newSelf->getLength()));
/* save the number string */
if (newSelf->NumberString != OREF_NULL) /* Did number convert OK? */
{
newSelf->setHasReferences(); /* Make sure we are sent Live... */
}
return newSelf->NumberString;
}
else
{ /* real primitive string */
/* get a new numberstring Obj */
OrefSet(this, this->NumberString, (RexxNumberString *)new_numberstring(this->getStringData(), this->getLength()));
if (this->NumberString == OREF_NULL) /* Did number convert OK? */
{
this->setNonNumeric(); /* mark as a nonnumeric */
}
else
{
this->setHasReferences(); /* Make sure we are sent Live... */
/* connect the string and number */
this->NumberString->setString(this);
}
return this->NumberString;
}
}
size_t RexxString::copyData(size_t startPos, char *buffer, size_t bufl)
/******************************************************************************/
/* Function: Get a section of a string and copy it into a buffer */
/******************************************************************************/
{
size_t copylen = 0;
if (startPos < this->getLength())
{
if (bufl <= this->getLength() - startPos)
{
copylen = bufl;
}
else
{
copylen = this->getLength() - startPos;
}
memcpy(buffer, this->getStringData() + startPos, (size_t)copylen);
}
return copylen;
}
RexxObject *RexxString::lengthRexx()
/******************************************************************************/
/* Function: Return the length of a string as an integer object */
/******************************************************************************/
{
/* return string byte length */
return new_integer(getLength());
}
bool RexxString::isEqual(
RexxObject *otherObj) /* other comparison object */
/******************************************************************************/
/* Function: Primitive strict equal\not equal method. This determines */
/* only strict equality, not greater or less than values. */
/******************************************************************************/
{
requiredArgument(otherObj, ARG_ONE); /* this is required. */
if (!this->isBaseClass()) /* not a primitive? */
{
/* do the full lookup compare */
return this->sendMessage(OREF_STRICT_EQUAL, otherObj)->truthValue(Error_Logical_value_method);
}
if (otherObj == TheNilObject) // strings never compare equal to the NIL object
{
return false;
}
RexxString *other = REQUEST_STRING(otherObj); /* force into string form */
size_t otherLen = other->getLength(); /* get length of second string. */
if (otherLen != this->getLength()) /* lengths different? */
{
return false; /* also unequal */
}
/* now compare the actual string */
return !memcmp(this->getStringData(), other->getStringData(), otherLen);
}
bool RexxString::primitiveIsEqual(
RexxObject *otherObj) /* other comparison object */
/******************************************************************************/
/* Function: Primitive strict equal\not equal method. This determines */
/* only strict equality, not greater or less than values. */
/******************************************************************************/
{
requiredArgument(otherObj, ARG_ONE); /* this is required. */
if (otherObj == TheNilObject) // strings never compare equal to the NIL object
{
return false;
}
RexxString *other = REQUEST_STRING(otherObj); /* force into string form */
size_t otherLen = other->getLength(); /* get length of second string. */
if (otherLen != this->getLength()) /* lengths different? */
{
return false; /* also unequal */
}
/* now compare the actual string */
return !memcmp(this->getStringData(), other->getStringData(), otherLen);
}
/**
* Primitive string caseless comparison.
*
* @param otherObj The other string to compare.
*
* @return true if the strings compare, false otherwise.
*/
bool RexxString::primitiveCaselessIsEqual(RexxObject *otherObj)
{
// we have one required string object
requiredArgument(otherObj, ARG_ONE);
if (otherObj == TheNilObject) // strings never compare equal to the NIL object
{
return false;
}
RexxString *other = REQUEST_STRING(otherObj);
stringsize_t otherLen = other->getLength();
// can't compare equal if different lengths
if (otherLen != this->getLength())
{
return false;
}
// do the actual string compare
return StringUtil::caselessCompare(this->getStringData(), other->getStringData(), otherLen) == 0;
}
/**
* Wrapper around the compareTo() method that validates and
* extracts integer value.
*
* @param other The other comparison object
*
* @return -1, 0, 1 depending on the comparison result.
*/
wholenumber_t RexxString::compareTo(RexxObject *other )
{
if (this->isBaseClass())
{
return compareToRexx((RexxString *)other, OREF_NULL, OREF_NULL)->getValue();
}
else
{
return RexxObject::compareTo(other);
}
}
wholenumber_t RexxString::comp(RexxObject *other)
/******************************************************************************/
/* Function: Do a value comparison of two strings for the non-strict */
/* comparisons. This returns for the compares: */
/* */
/* a value < 0 when this is smaller than other */
/* a value 0 when this is equal to other */
/* a value > 0 when this is larger than other */
/******************************************************************************/
{
RexxString *second; /* string value of other */
RexxNumberString *firstNum; /* numberstring value of this */
RexxNumberString *secondNum; /* numberstring value of other */
const char *firstStart; /* comparison start pointer */
const char *secondStart; /* other start pointer */
size_t firstLen; /* this compare length */
size_t secondLen; /* other compare length */
wholenumber_t result; /* compare result */
/* We need to see if the objects can */
/* be Converted to NumberString Objs */
/* 1st, this way we know if the COMP */
/* method of number String will */
/* succeed. Will only fail if an */
/* object cannot be represented as a */
/* number. This is important since */
/* NumberString calls String to do */
/* the compare if it can't, since */
/* this is the method NumberString */
/* will call, we must make sure a */
/* call to NumberString succeeds or */
/* we will get into a loop. */
requiredArgument(other, ARG_ONE); /* make sure we have a real argument */
if (other == TheNilObject) // all conditionals return .false when compared to .nil
{
return false;
}
/* try and convert both numbers */
if (((firstNum = this->fastNumberString()) != OREF_NULL) && ((secondNum = other->numberString()) != OREF_NULL ))
{
/* yes, send converted numbers and do*/
/* the compare */
return firstNum->comp(secondNum);
}
second = REQUEST_STRING(other); /* yes, get a string object. */
/* objects are converted. now strip */
/* any leading/trailing blanks. */
firstLen = this->getLength(); /* get the initial length */
firstStart = this->getStringData(); /* and starting position */
secondLen = second->getLength(); /* get length of second string. */
secondStart = second->getStringData(); /* get pointer to start of data */
/* while we have leading blanks. */
while (firstLen > 0 && (*firstStart == ch_BLANK || *firstStart == ch_TAB))
{
firstStart++; /* ignore character and look at next */
firstLen--; /* and string is now one char less. */
}
/* while we have leading blanks. */
while (secondLen > 0 && (*secondStart == ch_BLANK || *secondStart == ch_TAB))
{
secondStart++; /* ignore character and look at next */
secondLen--; /* and string is now one char less. */
}
if (firstLen >= secondLen)
{ /* determine the longer string. */
/* first string is larger, */
/* do a memory compare of strings, */
/* use length of smaller string. */
result = memcmp(firstStart, secondStart, (size_t) secondLen);
/* equal but different lengths? */
if ((result == 0) && (firstLen != secondLen))
{
/* point to first remainder char */
firstStart = firstStart + secondLen;
while (firstLen-- > secondLen)
{ /* while still have more to compare */
// Need unsigned char or chars above 0x7f will compare as less than
// blank.
unsigned char current = *firstStart++;
if (current != ch_BLANK && current != ch_TAB)
{
return current - ch_BLANK;
}
}
}
}
else
{ /* The length of second obj is longer*/
/* do memory compare of strings, use */
/* length of smaller string. */
result = memcmp(firstStart, secondStart, (size_t) firstLen);
if (result == 0)
{ /* if strings compared equal, we have*/
/* we need to compare the trailing */
/* part with blanks */
secondStart = secondStart + firstLen;
while (secondLen-- > firstLen)
{ /* while the longer string stills has*/
// Need unsigned char or chars above 0x7f will compare as less than
// blank.
unsigned char current = *secondStart++;
if (current != ch_BLANK && current != ch_TAB)
{
return ch_BLANK - current;
}
}
}
}
return result; /* return the compare result */
}
wholenumber_t RexxString::strictComp(RexxObject *otherObj)
/******************************************************************************/
/* Function: Do a strict comparison of two strings. This returns: */
/* */
/* a value < 0 when this is smaller than other */
/* a value 0 when this is equal to other */
/* a value > 0 when this is larger than other */
/******************************************************************************/
{
wholenumber_t result; /* compare result */
requiredArgument(otherObj, ARG_ONE); /* this is required. */
RexxString *other = REQUEST_STRING(otherObj); /* force into string form */
size_t otherLen = other->getLength(); /* get length of second string. */
const char *otherData = other->getStringData(); /* get pointer to start of data. */
if (this->getLength() >= otherLen)
{ /* determine the longer string. */
/* first string is larger, */
/* do a memory compare of strings, */
/* use length of smaller string. */
result = memcmp(this->getStringData(), otherData, (size_t) otherLen);
/* if strings are equal, and */
/* are not equal, the self is greater*/
if ((result == 0) && (this->getLength() > otherLen))
{
result = 1; /* otherwise they are equal. */
}
}
else
{ /* The length of second obj is longer*/
/* do memory compare of strings, use */
/* length of smaller string. */
result = memcmp(this->getStringData(), otherData, (size_t) this->getLength());
if (result == 0) /* if stings compared equal, */
{
result = -1; /* then the other string is bigger. */
}
}
return result; /* finished, return our result */
}
RexxObject *RexxString::plus(RexxObject *right_term)
/******************************************************************************/
/* Function: String addition...performed by RexxNumberString */
/******************************************************************************/
{
RexxNumberString *numstr; /* converted number string */
/* non-numeric? */
if ((numstr = this->fastNumberString()) == OREF_NULL)
{
/* this is a conversion error */
reportException(Error_Conversion_operator, this);
}
return numstr->plus(right_term); /* have numberstring do this */
}
RexxObject *RexxString::minus(RexxObject *right_term)
/******************************************************************************/
/* Function: String subtraction...performed by RexxNumberString */
/******************************************************************************/
{
RexxNumberString *numstr; /* converted number string */
/* non-numeric? */
if ((numstr = this->fastNumberString()) == OREF_NULL)
{
/* this is a conversion error */
reportException(Error_Conversion_operator, this);
}
return numstr->minus(right_term); /* have numberstring do this */
}
RexxObject *RexxString::multiply(RexxObject *right_term)
/******************************************************************************/
/* Function: String multiplication...performed by RexxNumberString */
/******************************************************************************/
{
RexxNumberString *numstr; /* converted number string */
/* non-numeric? */
if ((numstr = this->fastNumberString()) == OREF_NULL)
{
/* this is a conversion error */
reportException(Error_Conversion_operator, this);
}
return numstr->multiply(right_term); /* have numberstring do this */
}
RexxObject *RexxString::divide(RexxObject *right_term)
/******************************************************************************/
/* Function: String division...performed by RexxNumberString */
/******************************************************************************/
{
RexxNumberString *numstr; /* converted number string */
/* non-numeric? */
if ((numstr = this->fastNumberString()) == OREF_NULL)
{
/* this is a conversion error */
reportException(Error_Conversion_operator, this);
}
return numstr->divide(right_term); /* have numberstring do this */
}
RexxObject *RexxString::integerDivide(RexxObject *right_term)
/******************************************************************************/
/* Function: String division...performed by RexxNumberString */
/******************************************************************************/
{
RexxNumberString *numstr; /* converted number string */
/* non-numeric? */
if ((numstr = this->fastNumberString()) == OREF_NULL)
{
/* this is a conversion error */
reportException(Error_Conversion_operator, this);
}
return numstr->integerDivide(right_term); /* have numberstring do this */
}
RexxObject *RexxString::remainder(RexxObject *right_term)
/******************************************************************************/
/* Function: String division...performed by RexxNumberString */
/******************************************************************************/
{
RexxNumberString *numstr; /* converted number string */
/* non-numeric? */
if ((numstr = this->fastNumberString()) == OREF_NULL)
{
/* this is a conversion error */
reportException(Error_Conversion_operator, this);
}
return numstr->remainder(right_term); /* have numberstring do this */
}
RexxObject *RexxString::power(RexxObject *right_term)
/******************************************************************************/
/* Function: String division...performed by RexxNumberString */
/******************************************************************************/
{
RexxNumberString *numstr; /* converted number string */
/* non-numeric? */
if ((numstr = this->fastNumberString()) == OREF_NULL)
{
/* this is a conversion error */
reportException(Error_Conversion_operator, this);
}
return numstr->power(right_term); /* have numberstring do this */
}
RexxObject *RexxString::abs(void)
/******************************************************************************/
/* Function: String absolute value...performed by RexxNumberString */
/******************************************************************************/
{
RexxNumberString *numstr; /* converted number string */
/* non-numeric? */
if ((numstr = this->fastNumberString()) == OREF_NULL)
{
/* this is a conversion error */
reportException(Error_Incorrect_method_string_nonumber, CHAR_ABS, this);
}
return numstr->abs(); /* have numberstring do this */
}
RexxObject *RexxString::sign(void)
/******************************************************************************/
/* Function: String sign value...performed by RexxNumberString */
/******************************************************************************/
{
RexxNumberString *numstr; /* converted number string */
/* non-numeric? */
if ((numstr = this->fastNumberString()) == OREF_NULL)
{
/* this is a conversion error */
reportException(Error_Incorrect_method_string_nonumber, CHAR_SIGN, this);
}
return numstr->Sign(); /* have numberstring do this */
}
RexxObject *RexxString::Max(RexxObject **arguments, size_t argCount)
/******************************************************************************/
/* Function: String max value...performed by RexxNumberString */
/******************************************************************************/
{
RexxNumberString *numstr; /* converted number string */
/* non-numeric? */
if ((numstr = this->fastNumberString()) == OREF_NULL)
{
/* this is a conversion error */
reportException(Error_Incorrect_method_string_nonumber, CHAR_ORXMAX, this);
}
/* have numberstring do this */
return numstr->Max(arguments, argCount);
}
RexxObject *RexxString::Min(RexxObject **arguments, size_t argCount)
/******************************************************************************/
/* Function: String min value...performed by RexxNumberString */
/******************************************************************************/
{
RexxNumberString *numstr; /* converted number string */
/* non-numeric? */
if ((numstr = this->fastNumberString()) == OREF_NULL)
{
/* this is a conversion error */
reportException(Error_Incorrect_method_string_nonumber, CHAR_ORXMIN, this);
}
/* have numberstring do this */
return numstr->Min(arguments, argCount);
}
RexxObject *RexxString::trunc(RexxInteger *decimals)
/******************************************************************************/
/* Function: String Trunc...performed by RexxNumberString */
/******************************************************************************/
{
RexxNumberString *numstr; /* converted number string */
/* non-numeric? */
if ((numstr = this->fastNumberString()) == OREF_NULL)
{
/* this is a conversion error */
reportException(Error_Incorrect_method_string_nonumber, CHAR_TRUNC, this);
}
return numstr->trunc(decimals); /* have numberstring do this */
}
RexxObject *RexxString::format(RexxObject *Integers, RexxObject *Decimals, RexxObject *MathExp, RexxObject *ExpTrigger)
/******************************************************************************/
/* Function: String Format...performed by RexxNumberString */
/******************************************************************************/
{
RexxNumberString *numstr; /* converted number string */
/* non-numeric? */
if ((numstr = this->fastNumberString()) == OREF_NULL)
{
/* this is a conversion error */
reportException(Error_Incorrect_method_string_nonumber, CHAR_FORMAT, this);
}
/* have numberstring do this */
return numstr->formatRexx(Integers, Decimals, MathExp, ExpTrigger);
}
/**
* The string equals() method, which does a strict compare with
* another string object.
*
* @param other The other string object.
*
* @return True if the strings are equal, false for inequality.
*/
RexxInteger *RexxString::equals(RexxString *other)
{
return this->primitiveIsEqual(other) ? TheTrueObject : TheFalseObject;
}
/**
* The string equals() method, which does a strict caseless
* compare with another string object.
*
* @param other The other string object.
*
* @return True if the strings are equal, false for inequality.
*/
RexxInteger *RexxString::caselessEquals(RexxString *other)
{
return this->primitiveCaselessIsEqual(other) ? TheTrueObject : TheFalseObject;
}
RexxInteger *RexxString::strictEqual(RexxObject *other)
/******************************************************************************/
/* Function: Strict ("==") equality operator...also returns the hash value */
/* if sent with no other object */
/******************************************************************************/
{
return this->primitiveIsEqual(other) ? TheTrueObject : TheFalseObject;
}
RexxInteger *RexxString::strictNotEqual(RexxObject *other)
/******************************************************************************/
/* Function: Strict ("\==") inequality operator */
/******************************************************************************/
{
return !this->primitiveIsEqual(other) ? TheTrueObject : TheFalseObject;
}
RexxInteger *RexxString::equal(RexxObject *other)
/******************************************************************************/
/* Function: Non-strict ("=") string equality operator */
/******************************************************************************/
{
if (other == TheNilObject) // all conditionals return .false when compared to .nil
{
return TheFalseObject;
}
return ((this->comp(other) == 0) ? TheTrueObject : TheFalseObject);
}
RexxInteger *RexxString::notEqual(RexxObject *other)
/******************************************************************************/
/* Function: Non-Strict ("\=") string inequality operator */
/******************************************************************************/
{
if (other == TheNilObject) // all conditionals return .false when compared to .nil
{
return TheTrueObject;
}
return ((this->comp(other) != 0) ? TheTrueObject : TheFalseObject);
}
RexxInteger *RexxString::isGreaterThan(RexxObject *other)
/******************************************************************************/
/* Function: Non-strict greater than operator (">") */
/******************************************************************************/
{
if (other == TheNilObject) // all conditionals return .false when compared to .nil
{
return TheFalseObject;
}
return ((this->comp(other) > 0) ? TheTrueObject : TheFalseObject);
}
RexxInteger *RexxString::isLessThan(RexxObject *other)
/******************************************************************************/
/* Function: Non-strict less than operatore ("<") */
/******************************************************************************/
{
if (other == TheNilObject) // all conditionals return .false when compared to .nil
{
return TheFalseObject;
}
return ((this->comp(other) < 0) ? TheTrueObject : TheFalseObject);
}
RexxInteger *RexxString::isGreaterOrEqual(RexxObject *other)
/******************************************************************************/
/* Function: Non-strict greater than or equal operator (">=" or "\<") */
/******************************************************************************/
{
if (other == TheNilObject) // all conditionals return .false when compared to .nil
{
return TheFalseObject;
}
return ((this->comp(other) >= 0) ? TheTrueObject : TheFalseObject);
}
RexxInteger *RexxString::isLessOrEqual(RexxObject *other)
/******************************************************************************/
/* Function: Non-strict less than or equal operator ("<=" or "\>") */
/******************************************************************************/
{
if (other == TheNilObject) // all conditionals return .false when compared to .nil
{
return TheFalseObject;
}
return ((this->comp(other) <= 0) ? TheTrueObject : TheFalseObject);
}
RexxInteger *RexxString::strictGreaterThan(RexxObject *other)
/******************************************************************************/
/* Function: Strict greater than comparison (">>") */
/******************************************************************************/
{
if (other == TheNilObject) // all conditionals return .false when compared to .nil
{
return TheFalseObject;
}
return (this->strictComp(other) > 0) ? TheTrueObject : TheFalseObject;
}
RexxInteger *RexxString::strictLessThan(RexxObject *other)
/******************************************************************************/
/* Function: Strict less than comparison ("<<") */
/******************************************************************************/
{
if (other == TheNilObject) // all conditionals return .false when compared to .nil
{
return TheFalseObject;
}
return (this->strictComp(other) < 0) ? TheTrueObject : TheFalseObject;
}
RexxInteger *RexxString::strictGreaterOrEqual(RexxObject *other)
/******************************************************************************/
/* Function: Strict greater than or equal to comparison (">>=" or "\<<") */
/******************************************************************************/
{
if (other == TheNilObject) // all conditionals return .false when compared to .nil
{
return TheFalseObject;
}
return (this->strictComp(other) >= 0) ? TheTrueObject : TheFalseObject;
}
RexxInteger *RexxString::strictLessOrEqual(RexxObject *other)
/******************************************************************************/
/* Function: Strict less than or equal to operatore ("<<=" or "\>>") */
/******************************************************************************/
{
if (other == TheNilObject) // all conditionals return .false when compared to .nil
{
return TheFalseObject;
}
return (this->strictComp(other) <= 0) ? TheTrueObject : TheFalseObject;
}
RexxString *RexxString::concat(RexxString *other)
/******************************************************************************/
/* Function: Concatenate two strings together */
/******************************************************************************/
{
size_t len1; /* length of first string */
size_t len2; /* length of second string */
RexxString *result; /* result string */
char *data; /* character pointer */
len1 = this->getLength(); /* get this length */
len2 = other->getLength(); /* and the other length */
if (len2 == 0) // some people have taken to using a''b
{
// to perform concatenation operations
return this; // it makes sense to optimize concatenation
} // with a null string by just returning
if (len1 == 0) // the non-null object.
{
return other;
}
/* create a new string */
result = (RexxString *)raw_string(len1+len2);
data = result->getWritableData(); /* point to the string data */
// both lengths are non-zero because of the test above, so we can
// unconditionally copy
/* copy the front part */
memcpy(data, this->getStringData(), len1);
memcpy(data + len1, other->getStringData(), len2);
return result; /* return the result */
}
RexxString *RexxString::concatRexx(RexxObject *otherObj)
/******************************************************************************/
/* Function: Rexx level concatenate...requires conversion and checking */
/******************************************************************************/
{
size_t len1; /* length of first string */
size_t len2; /* length of second string */
RexxString *result; /* result string */
RexxString *other;
char *data; /* character pointer */
requiredArgument(otherObj, ARG_ONE); /* this is required. */
/* ensure a string value */
other = (RexxString *)REQUEST_STRING(otherObj);
/* added error checking for NULL pointer (from NilObject) */
if (other == OREF_NULL)
{
reportException(Error_Incorrect_method_nostring, IntegerOne);
}
/* the following logic also appears */
/* in string_concat, but is repeated */
/* here because this is a VERY high */
/* use function */
len1 = this->getLength(); /* get this length */
len2 = other->getLength(); /* and the other length */
/* create a new string */
result = (RexxString *)raw_string(len1+len2);
data = result->getWritableData(); /* point to the string data */
if (len1 != 0)
{ /* have real data? */
/* copy the front part */
memcpy(data, this->getStringData(), len1);
data += len1; /* step past the length */
}
if (len2 != 0) /* have a second length */
{
/* and the second part */
memcpy(data, other->getStringData(), len2);
}
return result; /* return the result */
}
RexxString *RexxString::concatToCstring(const char *other)
/******************************************************************************/
/* Function: Concatenate a string object onto an ASCII-Z string */
/******************************************************************************/
{
size_t len1; /* length of first string */
size_t len2; /* length of ASCII-Z string */
RexxString *result; /* result string */
len1 = this->getLength(); /* get this length */
len2 = strlen(other); /* and the other length */
/* create a new string */
result = (RexxString *)raw_string(len1+len2);
/* copy the front part */
memcpy(result->getWritableData(), other, len2);
/* and the second part */
memcpy(result->getWritableData() + len2, this->getStringData(), len1);
return result;
}
RexxString *RexxString::concatWithCstring(const char *other)
/******************************************************************************/
/* Function: Concatenate an ASCII-Z string onto a string object */
/******************************************************************************/
{
size_t len1; /* length of first string */
size_t len2; /* length of ASCII-Z string */
RexxString *result; /* result string */
len1 = this->getLength(); /* get this length */
len2 = strlen(other); /* and the other length */
/* create a new string */
result = (RexxString *)raw_string(len1+len2);
/* copy the string object */
memcpy(result->getWritableData(), this->getStringData(), len1);
/* copy the ASCII-Z string */
memcpy(result->getWritableData() + len1, other, len2);
return result;
}
RexxString *RexxString::concatBlank(RexxObject *otherObj)
/******************************************************************************/
/* Function: Concatenate two strings with a blank in between */
/******************************************************************************/
{
size_t len1; /* length of first string */
size_t len2; /* length of second string */
RexxString *result; /* result string */
RexxString *other; /* result string */
char *data; /* character pointer */
requiredArgument(otherObj, ARG_ONE); /* this is required. */
/* ensure a string value */
other = (RexxString *)REQUEST_STRING(otherObj);
/* added error checking for NULL pointer (from NilObject) */
if (other == OREF_NULL)
{
reportException(Error_Incorrect_method_nostring, IntegerOne);
}
/* ensure a string value */
other = (RexxString *)REQUEST_STRING(otherObj);
/* added error checking for NULL pointer (from NilObject) */
if (other == OREF_NULL)
{
reportException(Error_Incorrect_method_nostring, IntegerOne);
}
/* the following logic also appears */
/* in string_concat_with, but is */
/* repeated here because this is a */
/* VERY high use function */
len1 = this->getLength(); /* get this length */
len2 = other->getLength(); /* and the other length */
/* create a new string */
result = (RexxString *)raw_string(len1+len2+1);
data = result->getWritableData(); /* point to the string data */
if (len1 != 0)
{ /* have a first string? */
/* copy the front part */
memcpy(data, this->getStringData(), len1);
data += len1; /* step past the length */
}
*data++ = ' '; /* stuff in the seperating blank */
if (len2 != 0) /* have a second string? */
{
/* and the second part */
memcpy(data, other->getStringData(), len2);
}
return result;
}
bool RexxString::truthValue(int errorCode)
/******************************************************************************/
/* Function: Determine the truth value of a string object, raising the */
/* given error if bad. */
/******************************************************************************/
{
RexxString *testString; /* string to test */
if (!isOfClass(String, this)) /* a nonprimitive object? */
{
testString = this->requestString();/* get the real string value */
}
else
{
testString = this; /* just use the string directly */
}
if (testString->getLength() != 1) /* not exactly 1 character long? */
{
/* report the error */
reportException(errorCode, testString);
}
if (*(testString->getStringData()) == '0')/* exactly '0'? */
{
return false; /* have a false */
}
/* not exactly '1'? */
else if (!(*(testString->getStringData()) == '1'))
{
reportException(errorCode, this);/* report the error */
}
return true; /* this is true */
}
/**
* Convert an object to a logical value without raising an
* error.
*
* @param result The converted value.
*
* @return true if this converted ok, false for an invalid logical.
*/
bool RexxString::logicalValue(logical_t &result)
{
RexxString *testString; /* string to test */
if (!isOfClass(String, this)) /* a nonprimitive object? */
{
testString = this->requestString();/* get the real string value */
}
else
{
testString = this; /* just use the string directly */
}
if (testString->getLength() != 1) /* not exactly 1 character long? */
{
return false; // not a valid logical
}
if (testString->getChar(0) == '0')/* exactly '0'? */
{
result = false; // this is false and the conversion worked
return true;
}
/* exactly '1'? */
else if (testString->getChar(0) == '1')
{
result = true; // this is true and the conversion worked
return true;
}
return false; // did not convert correctly
}
bool RexxString::checkLower()
/******************************************************************************/
/* Function: Tests for existence of lowercase characters */
/******************************************************************************/
{
const char *data; /* current data pointer */
const char *endData; /* end location */
data = this->getStringData(); /* point to the string */
endData = data + this->getLength(); /* set the end point */
while (data < endData)
{ /* loop through entire string */
if (*data != toupper(*data))
{ /* have something to uppercase? */
this->setHasLower(); /* remember we have this */
return true; /* just return now */
}
data++; /* step the position */
}
/* no lowercase? */
this->setUpperOnly(); /* set the upper only attribute */
return false; /* return then translation flag */
}
RexxString *RexxString::upper()
/******************************************************************************/
/* Function: Translate a string to uppercase...will only create a new */
/* string if characters actually have to be translated. */
/******************************************************************************/
{
RexxString *newstring; /* newly created string */
const char *data; /* current data pointer */
char * outdata; /* output data */
const char *endData; /* end of the data */
/* something to uppercase? */
if (!this->upperOnly() && (this->hasLower() || this->checkLower()))
{
/* create a new string */
newstring = (RexxString *)raw_string(this->getLength());
data = this->getStringData(); /* point to the data start */
/* point to output data */
outdata = newstring->getWritableData();
endData = data + this->getLength(); /* set the loop terminator */
while (data < endData)
{ /* loop through entire string */
*outdata = toupper(*data); /* copy the uppercase character */
data++; /* step the position */
outdata++; /* and the output position */
}
newstring->setUpperOnly(); /* flag the string as uppercased */
return newstring; /* return the new string */
}
return this; /* return this unchanged */
}
RexxString *RexxString::stringTrace()
/******************************************************************************/
/* Function: Translate a string to "traceable" form, removing non-displayable*/
/* characters */
/******************************************************************************/
{
RexxString *newCopy; /* new copy of string */
// NOTE: since we're doing value comparisons on single character values here,
// we need to process this as unsigned characters to handle values
// greater than 0x7f.
const unsigned char *Current; /* current string location */
size_t i; /* string length */
bool NonDisplay; /* have non-displayables */
i = this->getLength(); /* get the length */
/* point to the start */
Current = (const unsigned char *)this->getStringData();
NonDisplay = false; /* no non-displayable characters */
for (; i > 0; i--)
{ /* loop for the entire string */
/* control character? */
if (*Current < ' ')
{
NonDisplay = true; /* got a non-displayable */
break; /* get out of here */
}
Current++; /* step the pointer */
}
if (!NonDisplay) /* all displayable? */
{
return this; /* leave unchanged */
}
/* copy the string */
newCopy = (RexxString *) this->copy();
i = newCopy->getLength(); /* get the length */
/* point to the start */
char *outptr = newCopy->getWritableData();
for (; i > 0; i--)
{ /* loop for the entire string */
/* control character? */
if (*outptr < ' ' && *outptr != '\t')
{
*outptr = '?'; /* yes, change to question */
}
outptr++; /* step the pointer */
}
return newCopy; /* return the converted string */
}
RexxString *RexxString::lower()
/******************************************************************************/
/* Function: Translate a string to lower case */
/******************************************************************************/
{
RexxString *newstring; /* newly created string */
const char * data; /* current data pointer */
char * outdata; /* output data */
size_t i; /* loop counter */
bool needTranslation; /* translation required */
data = this->getStringData(); /* point to the string */
needTranslation = false; /* no translation required */
for (i = 0; i < this->getLength(); i++)
{ /* loop through entire string */
if (*data != tolower(*data))
{ /* have something to lowercase? */
needTranslation = true; /* flag it */
break; /* stop at the first one */
}
data++; /* step the position */
}
if (needTranslation)
{ /* something to uppercase? */
/* create a new string */
newstring = (RexxString *)raw_string(this->getLength());
data = this->getStringData(); /* point to the data start */
/* point to output data */
outdata = newstring->getWritableData();
/* loop through entire string */
for (i = 0; i < this->getLength(); i++)
{
*outdata = tolower(*data); /* copy the lowercase character */
data++; /* step the position */
outdata++; /* and the output position */
}
}
else
{
newstring = this; /* return untranslated string */
}
return newstring; /* return the new copy */
}
/**
* Rexx exported method stub for the lower() method.
*
* @param start The optional starting location. Defaults to the first character
* if not specified.
* @param length The length to convert. Defaults to the segment from the start
* position to the end of the string.
*
* @return A new string object with the case conversion applied.
*/
RexxString *RexxString::lowerRexx(RexxInteger *_start, RexxInteger *_length)
{
size_t startPos = optionalPositionArgument(_start, 1, ARG_ONE) - 1;
size_t rangeLength = optionalLengthArgument(_length, getLength(), ARG_TWO);
// if we're starting beyond the end bounds, return unchanged
if (startPos >= getLength())
{
return this;
}
rangeLength = Numerics::minVal(rangeLength, getLength() - startPos);
// a zero length value is also a non-change.
if (rangeLength == 0)
{
return this;
}
return lower(startPos, rangeLength);
}
/**
* Rexx exported method stub for the upper() method.
*
* @param start The optional starting location. Defaults to the first character
* if not specified.
* @param length The length to convert. Defaults to the segment from the start
* position to the end of the string.
*
* @return A new string object with the case conversion applied.
*/
RexxString *RexxString::upperRexx(RexxInteger *_start, RexxInteger *_length)
{
size_t startPos = optionalPositionArgument(_start, 1, ARG_ONE) - 1;
size_t rangeLength = optionalLengthArgument(_length, getLength(), ARG_TWO);
// if we're starting beyond the end bounds, return unchanged
if (startPos >= getLength())
{
return this;
}
rangeLength = Numerics::minVal(rangeLength, getLength() - startPos);
// a zero length value is also a non-change.
if (rangeLength == 0)
{
return this;
}
return upper(startPos, rangeLength);
}
/**
* Lowercase a portion of a Rexx string, returning a new string object. This
* method assumes the offset and length are already valid
* for this string object.
*
* @param start The starting offset of the segment to lowercase (origin 0).
*
* @param length The length to lowercase.
*
* @return A new string object with the case conversion applied.
*/
RexxString *RexxString::lower(size_t offset, size_t _length)
{
// get a copy of the string
RexxString *newstring = extract(0, getLength());
char *data = newstring->getWritableData() + offset;
// now uppercase in place
for (size_t i = 0; i < _length; i++)
{
*data = tolower(*data);
data++;
}
return newstring;
}
/**
* Uppercase a portion of a Rexx string, returning a new string
* object. This method assumes the offset and length are
* already valid for this string object.
*
* @param start The starting offset of the segment to uppercase
* (origin 0).
*
* @param length The length to lowercase.
*
* @return A new string object with the case conversion applied.
*/
RexxString *RexxString::upper(size_t offset, size_t _length)
{
// get a copy of the string
RexxString *newstring = extract(0, getLength());
char *data = newstring->getWritableData() + offset;
// now uppercase in place
for (size_t i = 0; i < _length; i++)
{
*data = toupper(*data);
data++;
}
return newstring;
}
RexxInteger *RexxString::integerValue(
size_t digits) /* precision to use */
/******************************************************************************/
/* Function: Convert a string object to an integer. Returns .nil for */
/* failures. */
/******************************************************************************/
{
RexxNumberString *numberStr; /* string's numberstring version */
RexxInteger *newInteger; /* returned integer string */
/* Force String conversion through */
/* NumberString */
/* get the number string version */
if ((numberStr = this->fastNumberString()) != OREF_NULL )
{
/* try for an integer */
newInteger = numberStr->integerValue(digits);
/* did it convert? */
if (newInteger != TheNilObject && newInteger->getStringrep() == OREF_NULL)
{
newInteger->setString(this); /* connect the string value */
}
return newInteger; /* return the new integer */
}
else
{
return(RexxInteger *)TheNilObject;/* return .nil for failures */
}
}
void RexxString::setNumberString(RexxObject *NumberRep)
/******************************************************************************/
/* Function: Set a number string value on to the string */
/******************************************************************************/
{
OrefSet(this, this->NumberString, (RexxNumberString *)NumberRep);
if (NumberRep != OREF_NULL) /* actually get one? */
{
this->setHasReferences(); /* Make sure we are sent Live... */
}
else
{
this->setHasNoReferences(); /* no more references */
}
return;
}
RexxString *RexxString::concatWith(RexxString *other,
char between)
/******************************************************************************/
/* Function: Concatenate two strings with a single character between */
/******************************************************************************/
{
size_t len1; /* length of first string */
size_t len2; /* length of second string */
RexxString *result; /* result string */
char *data; /* character pointer */
len1 = this->getLength(); /* get this length */
len2 = other->getLength(); /* and the other length */
/* create a new string */
result = (RexxString *)raw_string(len1+len2+1);
data = result->getWritableData(); /* point to the string data */
if (len1 != 0)
{ /* have a first string? */
/* copy the front part */
memcpy(data, this->getStringData(), len1);
data += len1; /* step past the length */
}
*data++ = between; /* stuff in the seperating char */
if (len2 != 0) /* have a second string? */
{
/* and the second part */
memcpy(data, other->getStringData(), len2);
}
return result;
}
RexxObject *RexxString::andOp(RexxObject *other)
/******************************************************************************/
/* Function: Logical AND of a string with another logical value */
/******************************************************************************/
{
RexxObject *otherTruth; /* truth value of the other object */
requiredArgument(other, ARG_ONE); /* make sure the argument is there */
/* validate the boolean */
otherTruth = other->truthValue(Error_Logical_value_method) ? TheTrueObject : TheFalseObject;
/* perform the operation */
return(!this->truthValue(Error_Logical_value_method)) ? TheFalseObject : otherTruth;
}
RexxObject *RexxString::orOp(RexxObject *other)
/******************************************************************************/
/* Function: Logical OR of a string with another logical value */
/******************************************************************************/
{
RexxObject *otherTruth; /* truth value of the other object */
requiredArgument(other, ARG_ONE); /* make sure the argument is there */
/* validate the boolean */
otherTruth = other->truthValue(Error_Logical_value_method) ? TheTrueObject : TheFalseObject;
/* perform the operation */
return(this->truthValue(Error_Logical_value_method)) ? TheTrueObject : otherTruth;
}
RexxObject *RexxString::xorOp(RexxObject *other)
/******************************************************************************/
/* Function: Logical XOR of a string with another logical value */
/******************************************************************************/
{
requiredArgument(other, ARG_ONE); /* make sure the argument is there */
/* get as a boolean */
bool truth = other->truthValue(Error_Logical_value_method);
/* first one false? */
if (!this->truthValue(Error_Logical_value_method))
{
/* value is always the second */
return truth ? TheTrueObject : TheFalseObject;
}
else /* value is inverse of second */
{
return(truth) ? TheFalseObject : TheTrueObject;
}
}
RexxArray *RexxString::makeArrayRexx(RexxString *div)
/******************************************************************************/
/* Function: Split string into an array */
/******************************************************************************/
{
return StringUtil::makearray(getStringData(), getLength(), div);
}
RexxObject *RexxString::notOp()
/******************************************************************************/
/* Function: Logical NOT of a string */
/******************************************************************************/
{
return this->truthValue(Error_Logical_value_method) ? (RexxObject *)TheFalseObject : (RexxObject *)TheTrueObject;
}
RexxObject *RexxString::operatorNot(RexxObject *other)
/******************************************************************************/
/* Function: Logical NOT of a string */
/******************************************************************************/
{
return this->truthValue(Error_Logical_value_method) ? (RexxObject *)TheFalseObject : (RexxObject *)TheTrueObject;
}
RexxObject *RexxString::isInteger()
/******************************************************************************/
/* Function: Test if this string is an integer value */
/******************************************************************************/
{
const char *digitPtr;
size_t digitsLeft;
digitPtr = this->getStringData();
digitsLeft = this->getLength();
/* Skip all leading blanks */
for (; digitsLeft && (*digitPtr == ch_BLANK || *digitPtr == ch_TAB); ++digitPtr, --digitsLeft) ;
if (digitsLeft)
{ /* Still Digits left ? */
if (*digitPtr == ch_PLUS || *digitPtr == ch_MINUS)
{
/* need to move past the sign and */
/* remove any remaining blanks. */
for (++digitPtr, --digitsLeft;
digitsLeft && (*digitPtr == ch_BLANK || *digitPtr == ch_TAB);
++digitPtr, --digitsLeft) ;
/* Yes, skip any blanks */
if (!digitsLeft) /* Did we reach end of data ? */
{
/* Yes, not valid */
return TheFalseObject;
}
}
/* we are now ready to check for */
/*digits */
for (; digitsLeft && *digitPtr >= ch_ZERO && *digitPtr <= ch_NINE;
++digitPtr, --digitsLeft) ;
/* found our first non-digit, or end */
/* is it a decimal point? */
if ( digitsLeft && *digitPtr == ch_PERIOD)
{
digitPtr++; /* Yes, see if remaining digits are 0*/
digitsLeft--;
for (; digitsLeft && *digitPtr == ch_ZERO; ++digitPtr, --digitsLeft) ;
}
/* if chars left make sure all are */
/* blanks. */
for (; digitsLeft && (*digitPtr == ch_BLANK || *digitPtr == ch_TAB); ++digitPtr, --digitsLeft) ;
/* skipped all trailing blanks. */
/* we better be at the end of the */
/* string, otherwise its invalid. */
if (!digitsLeft)
{
/* yes its the end, return true */
return TheTrueObject;
}
}
/* all other cases are invalid.... */
return(RexxObject *) TheFalseObject;
}
RexxObject *RexxString::evaluate(
RexxActivation *context, /* current activation context */
RexxExpressionStack *stack ) /* evaluation stack */
/******************************************************************************/
/* Function: Polymorphic method that makes string a polymorphic expression */
/* term for string literals. */
/******************************************************************************/
{
stack->push((RexxObject *)this); /* place on the evaluation stack */
/* trace if necessary */
context->traceIntermediate((RexxObject *)this, TRACE_PREFIX_LITERAL);
return this; /* also return the result */
}
/**
* Copy a string to an RXSTRING, with appropriate allocation
* of a new buffer if required.
*
* @param r
*/
void RexxString::copyToRxstring(RXSTRING &r)
{
size_t result_length = getLength() + 1;
if (r.strptr == NULL || r.strlength < result_length)
{
r.strptr = (char *)SystemInterpreter::allocateResultMemory(result_length);
}
// copy all of the data + the terminating null
memcpy(r.strptr, getStringData(), result_length);
// fill in the length too
r.strlength = getLength();
}
RexxObject *RexxString::getValue(
RexxActivation *context) /* current activation context */
/******************************************************************************/
/* Function: Polymorphic get_value function used with expression terms */
/******************************************************************************/
{
return (RexxObject *)this; /* just return this value */
}
RexxObject *RexxString::getValue(
RexxVariableDictionary *context) /* current activation context */
/******************************************************************************/
/* Function: Polymorphic get_value function used with expression terms */
/******************************************************************************/
{
return (RexxObject *)this; /* just return this value */
}
RexxObject *RexxString::getRealValue(
RexxActivation *context) /* current activation context */
/******************************************************************************/
/* Function: Polymorphic get_value function used with expression terms */
/******************************************************************************/
{
return (RexxObject *)this; /* just return this value */
}
RexxObject *RexxString::getRealValue(
RexxVariableDictionary *context) /* current activation context */
/******************************************************************************/
/* Function: Polymorphic get_value function used with expression terms */
/******************************************************************************/
{
return (RexxObject *)this; /* just return this value */
}
RexxString *RexxString::newString(const char *string, size_t length)
/******************************************************************************/
/* Function: Allocate (and initialize) a string object */
/******************************************************************************/
{
/* calculate the size */
/* STRINGOBJ - excess chars (3) */
/* + length. only sub 3 to allow */
/* for terminating NULL */
size_t size2 = sizeof(RexxString) - (sizeof(char) * 3) + length;
/* allocate the new object */
RexxString *newObj = (RexxString *)new_object(size2, T_String);
/* clear the front part */
newObj->setLength(length); /* save the length */
newObj->hashValue = 0; // make sure the hash value is zeroed
/* Null terminate, allows faster */
/* conversion to ASCII-Z string */
newObj->putChar(length, '\0');
/* copy it over */
newObj->put(0, string, length);
/* by default, we don't need Live */
newObj->setHasNoReferences(); /*sent */
/* NOTE: That if we can set */
/* this->NumebrString elsewhere */
/*we need to mark ourselves as */
return newObj; /*having OREFs */
}
RexxString *RexxString::rawString(size_t length)
/******************************************************************************/
/* Function: Allocate (and initialize) an empty string object */
/******************************************************************************/
{
/* calculate the size */
/* STRINGOBJ - excess chars (3) */
/* + length. only sub 3 to allow */
/* for terminating NULL */
size_t size2 = sizeof(RexxString) - (sizeof(char) * 3) + length;
/* allocate the new object */
RexxString *newObj = (RexxString *)new_object(size2, T_String);
newObj->setLength(length); /* save the length */
newObj->hashValue = 0; // make sure the hash value is zeroed
/* Null terminate, allows faster */
/* conversion to ASCII-Z string */
newObj->putChar(length, '\0');
/* by default, we don't need Live */
newObj->setHasNoReferences(); /*sent */
/* NOTE: That if we can set */
/* this->NumebrString elsewhere */
/*we need to mark ourselves as */
return newObj; /*having OREFs */
}
/**
* Allocate an initialize a string object that will also
* contain only uppercase characters. This allows a creation
* and uppercase operation to be done in one shot, without
* requiring two string objects to be created.
*
* @param string The source string data.
* @param length The length of the string data.
*
* @return A newly constructed string object.
*/
RexxString *RexxString::newUpperString(const char * string, stringsize_t length)
{
/* calculate the size */
/* STRINGOBJ - excess chars (3) */
/* + length. only sub 3 to allow */
/* for terminating NULL */
size_t size2 = sizeof(RexxString) - (sizeof(char) * 3) + length;
/* allocate the new object */
RexxString *newObj = (RexxString *)new_object(size2, T_String);
newObj->length = length; /* save the length */
newObj->hashValue = 0; // make sure the hash value is zeroed
/* create a new string */
/* point to output data */
char *outdata = newObj->getWritableData();
// set the input markers
const char *indata = string;
const char *endData = indata + length;
while (indata < endData) /* loop through entire string */
{
*outdata = toupper(*indata); /* copy the uppercase character */
indata++; /* step the position */
outdata++; /* and the output position */
}
newObj->setUpperOnly(); /* flag the string as uppercased */
/* Null terminate, allows faster */
/* conversion to ASCII-Z string */
newObj->putChar(length, '\0');
/* by default, we don't need Live */
newObj->setHasNoReferences(); /*sent */
/* NOTE: That if we can set */
/* this->NumebrString elsewhere */
/*we need to mark ourselves as */
return newObj; /*having OREFs */
}
RexxString *RexxString::newString(double number)
/******************************************************************************/
/* Function: Create a string from a double value */
/******************************************************************************/
{
/* get double as a number string. */
return new_numberstringFromDouble(number)->stringValue();
}
/**
* Convert a double value to a string using the provided
* precision.
*
* @param number The number to convert.
* @param precision The precision requested for the result.
*
* @return A string value of the converted result.
*/
RexxString *RexxString::newString(double number, stringsize_t precision)
{
if (number == 0) /* zero result? */
{
return new_string("0");
}
else
{
char buffer[64];
// format as a string
sprintf(buffer, "%.*g", (int)precision, number);
size_t len = strlen(buffer);
// if the last character is a decimal, we remove that
if (buffer[len - 1] == '.')
{
len--;
}
return new_string(buffer, len);
}
}
RexxString *RexxString::newProxy(const char *string)
/******************************************************************************/
/* Function: Create a proxy object from this string */
/******************************************************************************/
{
RexxString *sref;
/* The provided source string is null*/
/* terminated so let class_new */
/* compute the length. */
/* get a new string object */
sref = (RexxString *)new_string(string);
/* here we need to identify this */
/*string */
sref->makeProxiedObject(); /* as being a proxy object */
return sref;
}
RexxString *RexxString::newRexx(RexxObject **init_args, size_t argCount)
/******************************************************************************/
/* Arguments: Subclass init arguments */
/* Function: Create a new string value (used primarily for subclasses) */
/******************************************************************************/
{
RexxObject *stringObj; /* string value */
/* break up the arguments */
RexxClass::processNewArgs(init_args, argCount, &init_args, &argCount, 1, (RexxObject **)&stringObj, NULL);
/* force argument to string value */
RexxString *string = (RexxString *)stringArgument(stringObj, ARG_ONE);
/* create a new string object */
string = new_string(string->getStringData(), string->getLength());
ProtectedObject p(string);
string->setBehaviour(((RexxClass *)this)->getInstanceBehaviour());
if (((RexxClass *)this)->hasUninitDefined())
{
string->hasUninit();
}
/* Initialize the new instance */
string->sendMessage(OREF_INIT, init_args, argCount);
return string; /* return the new string */
}
PCPPM RexxString::operatorMethods[] =
{
NULL, /* first entry not used */
(PCPPM)&RexxString::plus,
(PCPPM)&RexxString::minus,
(PCPPM)&RexxString::multiply,
(PCPPM)&RexxString::divide,
(PCPPM)&RexxString::integerDivide,
(PCPPM)&RexxString::remainder,
(PCPPM)&RexxString::power,
(PCPPM)&RexxString::concatRexx,
(PCPPM)&RexxString::concatRexx,
(PCPPM)&RexxString::concatBlank,
(PCPPM)&RexxString::equal,
(PCPPM)&RexxString::notEqual,
(PCPPM)&RexxString::isGreaterThan,
(PCPPM)&RexxString::isLessOrEqual,
(PCPPM)&RexxString::isLessThan,
(PCPPM)&RexxString::isGreaterOrEqual,
/* Duplicate entry neccessary */
(PCPPM)&RexxString::isGreaterOrEqual,
(PCPPM)&RexxString::isLessOrEqual,
(PCPPM)&RexxString::strictEqual,
(PCPPM)&RexxString::strictNotEqual,
(PCPPM)&RexxString::strictGreaterThan,
(PCPPM)&RexxString::strictLessOrEqual,
(PCPPM)&RexxString::strictLessThan,
(PCPPM)&RexxString::strictGreaterOrEqual,
/* Duplicate entry neccessary */
(PCPPM)&RexxString::strictGreaterOrEqual,
(PCPPM)&RexxString::strictLessOrEqual,
(PCPPM)&RexxString::notEqual,
(PCPPM)&RexxString::notEqual, /* Duplicate entry neccessary */
(PCPPM)&RexxString::andOp,
(PCPPM)&RexxString::orOp,
(PCPPM)&RexxString::xorOp,
(PCPPM)&RexxString::operatorNot,
};