StringClass.hpp
Go to the documentation of this file.
1 /*----------------------------------------------------------------------------*/
2 /* */
3 /* Copyright (c) 1995, 2004 IBM Corporation. All rights reserved. */
4 /* Copyright (c) 2005-2009 Rexx Language Association. All rights reserved. */
5 /* */
6 /* This program and the accompanying materials are made available under */
7 /* the terms of the Common Public License v1.0 which accompanies this */
8 /* distribution. A copy is also available at the following address: */
9 /* http://www.oorexx.org/license.html */
10 /* */
11 /* Redistribution and use in source and binary forms, with or */
12 /* without modification, are permitted provided that the following */
13 /* conditions are met: */
14 /* */
15 /* Redistributions of source code must retain the above copyright */
16 /* notice, this list of conditions and the following disclaimer. */
17 /* Redistributions in binary form must reproduce the above copyright */
18 /* notice, this list of conditions and the following disclaimer in */
19 /* the documentation and/or other materials provided with the distribution. */
20 /* */
21 /* Neither the name of Rexx Language Association nor the names */
22 /* of its contributors may be used to endorse or promote products */
23 /* derived from this software without specific prior written permission. */
24 /* */
25 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS */
26 /* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT */
27 /* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS */
28 /* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT */
29 /* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
30 /* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED */
31 /* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, */
32 /* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY */
33 /* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */
34 /* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
35 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
36 /* */
37 /*----------------------------------------------------------------------------*/
38 /******************************************************************************/
39 /* REXX Kernel StringClass.hpp */
40 /* */
41 /* Primitive String Class Definition */
42 /* */
43 /******************************************************************************/
44 #ifndef Included_RexxString
45 #define Included_RexxString
46 
47 #include "NumberStringClass.hpp"
48 #include "IntegerClass.hpp"
49 #include "StringUtil.hpp"
50 #include "Utilities.hpp"
51 
52  /* return values from the is_symbol */
53  /* validation method */
54 #define STRING_BAD_VARIABLE 0
55 #define STRING_STEM 1
56 #define STRING_COMPOUND_NAME 2
57 #define STRING_LITERAL 3
58 #define STRING_LITERAL_DOT 4
59 #define STRING_NUMERIC 5
60 #define STRING_NAME 6
61 
62 #define STRING_HASLOWER 0x01 /* string does contain lowercase */
63 #define STRING_NOLOWER 0x02 /* string does not contain lowercase */
64 #define STRING_NONNUMERIC 0x04 /* string is non-numeric */
65 #define STRING_ISASCII_CHECKED 0x08 /* string is ASCII only checked */
66 #define STRING_ISASCII 0x10 /* string is ASCII only */
67 
68 #define INITIAL_NAME_SIZE 10 /* first name table allocation */
69 #define EXTENDED_NAME_SIZE 10 /* amount to extend table by */
70  /* Strip function options */
71 #define STRIP_BOTH 'B'
72 #define STRIP_LEADING 'L'
73 #define STRIP_TRAILING 'T'
74  /* Datatype function options */
75 #define DATATYPE_ALPHANUMERIC 'A'
76 #define DATATYPE_BINARY 'B'
77 #define DATATYPE_LOWERCASE 'L'
78 #define DATATYPE_MIXEDCASE 'M'
79 #define DATATYPE_NUMBER 'N'
80 #define DATATYPE_SYMBOL 'S'
81 #define DATATYPE_VARIABLE 'V'
82 #define DATATYPE_UPPERCASE 'U'
83 #define DATATYPE_WHOLE_NUMBER 'W'
84 #define DATATYPE_HEX 'X'
85 #define DATATYPE_9DIGITS '9'
86 #define DATATYPE_LOGICAL 'O' // lOgical.
87  /* Verify function options */
88 #define VERIFY_MATCH 'M'
89 #define VERIFY_NOMATCH 'N'
90 
91 #define ch_SPACE ' '
92 
93  /* character validation sets for the */
94  /* datatype function */
95 #define HEX_CHAR_STR "0123456789ABCDEFabcdef"
96 #define ALPHANUM \
97 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
98 #define BINARI "01"
99 #define LOWER_ALPHA "abcdefghijklmnopqrstuvwxyz"
100 #define MIXED_ALPHA \
101 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
102 #define UPPER_ALPHA "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
103 
104 
105 /*********************************************************************/
106 /* */
107 /* Name: IntToHexdigit */
108 /* */
109 /* Descriptive name: convert int to hexadecimal digit */
110 /* */
111 /* Returns: A hexadecimal digit representing n. */
112 /* */
113 /*********************************************************************/
114 
115  /* convert the number */
116 inline char IntToHexDigit(int n)
117 {
118  return "0123456789ABCDEF"[n];
119 }
120 
121  class RexxString : public RexxObject {
122  public:
123  inline void *operator new(size_t size, void *ptr){return ptr;};
124  inline RexxString() {;} ;
125  inline RexxString(RESTORETYPE restoreType) { ; };
126 
127  void live(size_t);
128  void liveGeneral(int reason);
129  void flatten(RexxEnvelope *envelope);
131 
132  virtual HashCode hash();
133  virtual HashCode getHashValue();
134 
136  {
137  if (hashValue == 0) // if we've never generated this, the code is zero
138  {
139  stringsizeB_t len = this->getBLength();
140 
141  HashCode h = 0;
142  // the hash code is generated from all of the string characters.
143  // we do this in a lazy fashion, since most string objects never need to
144  // calculate a hash code, particularly the long ones.
145  // This hashing algorithm is very similar to that used for Java strings.
146  for (stringsizeB_t i = 0; i < len; i++)
147  {
148  h = 31 * h + this->stringData[stringsize_v(i)];
149  }
150  this->hashValue = h;
151  }
152  return hashValue;
153  }
155 
156  bool numberValue(wholenumber_t &result, size_t precision);
157  bool numberValue(wholenumber_t &result);
158  bool unsignedNumberValue(uwholenumber_t &result, size_t precision);
159  bool unsignedNumberValue(uwholenumber_t &result);
160  bool doubleValue(double &result);
162  RexxInteger *integerValue(size_t precision);
164  RexxArray *makeArray();
166  void copyIntoTail(RexxCompoundTail *buffer);
168  bool truthValue(int);
169  virtual bool logicalValue(logical_t &);
170 
171  bool isEqual(RexxObject *); // in behaviour
174  wholenumber_t strictComp(RexxObject *, RexxString *alternativeOperator=NULL, RexxInteger **alternativeOperatorResultPtr=NULL);
175  wholenumber_t comp(RexxObject *, RexxString *alternativeOperator=OREF_NULL, RexxInteger **alternativeOperatorResultPtr=NULL);
178  RexxInteger *strictEqual(RexxObject *); // in behaviour
179  RexxInteger *notEqual(RexxObject *); // in behaviour
180  RexxInteger *strictNotEqual(RexxObject *); // in behaviour
181  RexxInteger *isGreaterThan(RexxObject *); // in behaviour
182  RexxInteger *isLessThan(RexxObject *); // in behaviour
183  RexxInteger *isGreaterOrEqual(RexxObject *); // in behaviour
184  RexxInteger *isLessOrEqual(RexxObject *); // in behaviour
185  RexxInteger *strictGreaterThan(RexxObject *); // in behaviour
186  RexxInteger *strictLessThan(RexxObject *); // in behaviour
187  RexxInteger *strictGreaterOrEqual(RexxObject *); // in behaviour
188  RexxInteger *strictLessOrEqual(RexxObject *); // in behaviour
189 
190  sizeB_t copyData(sizeB_t, char *, sizeB_t);
191  RexxObject *lengthRexx(); // in behaviour
192  RexxString *concatRexx(RexxObject *); // in behaviour
194  RexxString *concatToCstring(const char *);
195  RexxString *concatWithCstring(const char *);
196  RexxString *concatBlank(RexxObject *); // in behaviour
197  bool checkLower();
198  bool checkIsASCII();
200  RexxString *upper();
202  RexxString *upperRexx(RexxInteger *, RexxInteger *); // in behaviour
203  RexxString *lower();
205  RexxString *lowerRexx(RexxInteger *, RexxInteger *); // in behaviour
207  void setNumberString(RexxObject *);
208  RexxString *concatWith(RexxString *, char);
209 
210  RexxObject *plus(RexxObject *right); // in behaviour
211  RexxObject *minus(RexxObject *right); // in behaviour
212  RexxObject *multiply(RexxObject *right); // in behaviour
213  RexxObject *divide(RexxObject *right); // in behaviour
214  RexxObject *integerDivide(RexxObject *right); // in behaviour
215  RexxObject *remainder(RexxObject *right); // in behaviour
216  RexxObject *power(RexxObject *right); // in beahviour
217  RexxObject *abs(); // in behaviour
218  RexxObject *sign(); // in behaviour
219  RexxObject *notOp(); // in beahviour
221  RexxObject *andOp(RexxObject *); // in behaviour
222  RexxObject *orOp(RexxObject *); // in behaviour
223  RexxObject *xorOp(RexxObject *); // in behaviour
224  RexxObject *Max(RexxObject **args, size_t argCount, size_t named_argCount); // in behaviour
225  RexxObject *Min(RexxObject **args, size_t argCount, size_t named_argCount); // in behaviour
226  RexxObject *trunc(RexxInteger *decimals); // in behaviour
227  RexxObject *floor();
228  RexxObject *ceiling();
229  RexxObject *round();
230  RexxObject *format(RexxObject *Integers, RexxObject *Decimals, RexxObject *MathExp, RexxObject *ExpTrigger); // in behaviour
233  RexxString *extract(size_t offset, size_t sublength) { return newString(getStringData() + offset, sublength); }
234  RexxString *extractB(sizeB_t offset, sizeB_t sublength) // Extract bytes
235  {
236  return newString(getStringData() + offset, sublength);
237  }
238  RexxString *extractC(sizeC_t offset, sizeC_t sublength) // Extract characters
239  {
240  return newString(getStringData() + size_v(offset), size_v(sublength), sublength); // todo m17n
241  }
247  /* the following methods are in */
248  /* OKBSUBS */
249  RexxString *center(RexxInteger *, RexxString *); // in behaviour
250  RexxString *delstr(RexxInteger *, RexxInteger *); // in behaviour
251  RexxString *insert(RexxString *, RexxInteger *, RexxInteger *, RexxString *); // in behaviour
252  RexxString *left(RexxInteger *, RexxString *); // in behaviour
253  RexxString *overlay(RexxString *, RexxInteger *, RexxInteger *, RexxString *); // in behaviour
254  RexxString *replaceAt(RexxString *, RexxInteger *, RexxInteger *, RexxString *); // in behaviour
255  RexxString *reverse(); // in behaviour
256  RexxString *right(RexxInteger *, RexxString *); // in behaviour
257  RexxString *strip(RexxString *, RexxString *); // in behaviour
258  RexxString *substr(RexxInteger *, RexxInteger *, RexxString *); // in behaviour
259  RexxString *subchar(RexxInteger *); // in behaviour
260  RexxString *delWord(RexxInteger *, RexxInteger *); // in behaviour
261  RexxString *space(RexxInteger *, RexxString *); // in behaviour
262  RexxString *subWord(RexxInteger *, RexxInteger *); // in behaviour
263  RexxArray *subWords(RexxInteger *, RexxInteger *); // in behaviour
264  RexxString *word(RexxInteger *); // in behaviour
265  RexxInteger *wordIndex(RexxInteger *); // in behaviour
266  RexxInteger *wordLength(RexxInteger *); // in behaviour
267  RexxInteger *wordPos(RexxString *, RexxInteger *); // in behaviour
268  RexxInteger *caselessWordPos(RexxString *, RexxInteger *); // in behaviour
269  RexxInteger *words(); // in behaviour
270  /* the following methods are in */
271  /* OKBMISC */
272  RexxString *changeStr(RexxString *, RexxString *, RexxInteger *); // in behaviour
274  RexxInteger *abbrev(RexxString *, RexxInteger *); // in behaviour
275  RexxInteger *caselessAbbrev(RexxString *, RexxInteger *); // in behaviour
276  RexxInteger *compare(RexxString *, RexxString *); // in behaviour
277  RexxInteger *caselessCompare(RexxString *, RexxString *); // in behaviour
278  RexxString *copies(RexxInteger *); // in behaviour
279  RexxObject *dataType(RexxString *); // in behaviour
280 
281  RexxInteger *lastPosRexx(RexxString *, RexxInteger *, RexxInteger *); // in behaviour
285  const char * caselessLastPos(const char *needle, sizeB_t needleLen, const char *haystack, sizeB_t haystackLen);
286 
287  RexxInteger *posRexx(RexxString *, RexxInteger *, RexxInteger *); // in behaviour
291 
293  RexxInteger *verify(RexxString *, RexxString *, RexxInteger *, RexxInteger *); // in behaviour
294  RexxInteger *countStrRexx(RexxString *); // in behaviour
295  RexxInteger *caselessCountStrRexx(RexxString *); // in behaviour
297  /* the following methods are in */
298  /* OKBBITS */
299  RexxString *bitAnd(RexxString *, RexxString *); // in behaviour
300  RexxString *bitOr(RexxString *, RexxString *); // in behaviour
301  RexxString *bitXor(RexxString *, RexxString *); // in behaviour
302  /* the following methods are in */
303  /* OKBCONV */
304  RexxString *b2x(); // in behaviour
305  RexxString *c2d(RexxInteger *); // in behaviour
306  RexxString *c2x(); // in behaviour
307  RexxString *encodeBase64(); // in behaviour
308  RexxString *decodeBase64(); // in behaviour
309  RexxString *d2c(RexxInteger *); // in behaviour
310  RexxString *d2x(RexxInteger *); // in behaviour
311  RexxString *x2b(); // in behaviour
312  RexxString *x2c(); // in behaviour
313  RexxString *x2d(RexxInteger *); // in behaviour
314  RexxString *x2dC2d(RexxInteger *, bool);
315 
316  RexxInteger *match(RexxInteger *start_, RexxString *other, RexxInteger *offset_, RexxInteger *len_); // in behaviour
317  RexxInteger *caselessMatch(RexxInteger *start_, RexxString *other, RexxInteger *offset_, RexxInteger *len_); // in behaviour
320  RexxInteger *matchChar(RexxInteger *position_, RexxString *matchSet); // in behaviour
321  RexxInteger *caselessMatchChar(RexxInteger *position_, RexxString *matchSet); // in behaviour
322 
323  RexxInteger *compareToRexx(RexxString *other, RexxInteger *start_, RexxInteger *len_); // in behaviour
324  RexxInteger *caselessCompareToRexx(RexxString *other, RexxInteger *start_, RexxInteger *len_); // in behaviour
327 
328  RexxInteger *equals(RexxString *other); // in behaviour
329  RexxInteger *caselessEquals(RexxString *other); // in behaviour
330 
331  RexxArray *makeArrayRexx(RexxString *); // in behaviour
332 
333 /****************************************************************************/
334 /* */
335 /* RexxString Methods in OKBMISC.C */
336 /* */
337 /****************************************************************************/
338  int isSymbol();
339 
340 /* Inline_functions */
341 
342  inline sizeB_t getBLength() { return this->blength; };
343  inline sizeC_t getCLength() { return this->clength; };
344  inline void setBLength(sizeB_t l) { this->blength = l; };
345  inline void setCLength(sizeC_t l) { this->clength = l; };
346  inline void finish(stringsizeB_t bl, sizeC_t cl=-1)
347  {
348  this->blength = bl;
349  this->clength =
350  cl == -1 ?
351  sizeC_v(size_v(bl)) // todo m17n: calculate length in characters
352  :
353  cl;
354  }
355  inline const char *getStringData() { return this->stringData; };
356  inline char *getWritableData() { return &this->stringData[0]; };
357  inline void put(sizeB_t s, const void *b, sizeB_t l) { memcpy(getWritableData() + s, b, l); };
358  inline void put(sizeB_t s, RexxString *o) { put(s, o->getStringData(), o->getBLength()); }; // todo m17n ? for the moment I use sizeB_t, like previous put method.
359  inline void set(sizeB_t s,int c, sizeB_t l) { memset((this->stringData + s), c, l); };
360  inline char getCharB(sizeB_t p) { return *(this->stringData+p); }; // m17n : returns a byte, not a codepoint
361  inline codepoint_t getCharC(sizeC_t p) { return *(this->stringData+size_v(p)); }; // todo call m17n : convert charpos to bytepos and return a codepoint, not a byte
362  inline char putCharB(sizeB_t p,char c) { return *(this->stringData+p) = c; }; // m17n : stores a byte, not a codepoint
363  //inline char putCharC(sizeC_t p,codepoint_t c) { return *(this->stringData+p) = c; }; // todo call m17n : stores a codepoint (ako replaceChar ? i.e. string can grow or shrink when utf-8 ? or is it limited to pure ascii chars <= 0x7F ?)
364 
365  inline bool upperOnly() {return (this->Attributes&STRING_NOLOWER) != 0;};
366  inline bool hasLower() {return (this->Attributes&STRING_HASLOWER) != 0;};
367  inline void setUpperOnly() { this->Attributes |= STRING_NOLOWER;};
368  inline void setHasLower() { this->Attributes |= STRING_HASLOWER;};
369  inline bool nonNumeric() {return (this->Attributes&STRING_NONNUMERIC) != 0;};
370  inline void setNonNumeric() { this->Attributes |= STRING_NONNUMERIC;};
371  inline bool isASCIIChecked() {return (this->Attributes & STRING_ISASCII_CHECKED) != 0;};
373  inline bool isASCII() {return (this->Attributes & STRING_ISASCII) != 0;};
374  inline void setIsASCII() {this->Attributes |= STRING_ISASCII;};
375 
376  inline bool strCompare(const char * s) {return this->memCompare((s), strlen(s));};
377  inline bool strCaselessCompare(const char * s) { return this->blength == strlen(s) && Utilities::strCaselessCompare(s, this->stringData) == 0;}
378  inline bool memCompare(const char * s, sizeB_t l) { return l == this->blength && memcmp(s, this->stringData, l) == 0; }
379  inline bool memCompare(RexxString *other)
380  {
381  return other->blength == this->blength &&
382  memcmp(other->stringData, this->stringData, blength) == 0;
383  }
384  inline void memCopy(char * s) { memcpy(s, stringData, blength); }
385  inline void toRxstring(CONSTRXSTRING &r) { r.strptr = getStringData(); r.strlength = size_v(getBLength()); } // no encoding support, so better to use blength
387  void copyToRxstring(RXSTRING &r);
388  inline bool endsWith(codepoint_t c) { return getCLength() > 0 && this->getCharC(this->getCLength() - 1) == c; }
389 
391 
393  if (this->nonNumeric()) /* Did we already try and convert to */
394  /* to a numberstring and fail? */
395  return OREF_NULL; /* Yes, no need to try agian. */
396 
397  if (this->NumberString != OREF_NULL) /* see if we have already converted */
398  return this->NumberString; /* return the numberString Object. */
399  return createNumberString(); /* go build the number string version */
400  }
401 
402  inline int sortCompare(RexxString *other) {
403  sizeB_t compareLength = blength;
404  if (compareLength > other->blength) {
405  compareLength = other->blength;
406  }
407  int result = memcmp(stringData, other->stringData, compareLength);
408  if (result == 0) {
409  if (blength > other->blength) {
410  result = 1;
411  }
412  else if (blength < other->blength) {
413  result = -1;
414  }
415  }
416  return result;
417  }
418 
419  inline int sortCaselessCompare(RexxString *other) {
420  sizeB_t compareLength = blength;
421  if (compareLength > other->blength) {
422  compareLength = other->blength;
423  }
424  int result = StringUtil::caselessCompare(stringData, other->stringData, compareLength);
425  if (result == 0) {
426  if (blength > other->blength) {
427  result = 1;
428  }
429  else if (blength < other->blength) {
430  result = -1;
431  }
432  }
433  return result;
434  }
435 
436  inline int sortCompare(RexxString *other, sizeC_t startCol, sizeC_t colLength) {
437  int result = 0;
438  if ((startCol < clength ) && (startCol < other->clength)) {
439  sizeC_t stringLength = clength;
440  if (stringLength > other->clength) {
441  stringLength = other->clength;
442  }
443  stringLength = stringLength - startCol + 1;
444  sizeC_t compareLength = colLength;
445  if (compareLength > stringLength) {
446  compareLength = stringLength;
447  }
448 
449  result = memcmp(stringData + size_v(startCol), other->stringData + size_v(startCol), size_v(compareLength)); // todo m17n
450  if (result == 0 && stringLength < colLength) {
451  if (clength > other->clength) {
452  result = 1;
453  }
454  else if (clength < other->clength) {
455  result = -1;
456  }
457  }
458  }
459  else {
460  if (clength == other->clength) {
461  result = 0;
462  }
463  else {
464  result = clength < other->clength ? -1 : 1;
465  }
466  }
467  return result;
468  }
469 
470  inline int sortCaselessCompare(RexxString *other, sizeC_t startCol, sizeC_t colLength) {
471  int result = 0;
472  if ((startCol < clength ) && (startCol < other->clength)) {
473  sizeC_t stringLength = clength;
474  if (stringLength > other->clength) {
475  stringLength = other->clength;
476  }
477  stringLength = stringLength - startCol + 1;
478  sizeC_t compareLength = colLength;
479  if (compareLength > stringLength) {
480  compareLength = stringLength;
481  }
482 
483  result = StringUtil::caselessCompare(stringData + size_v(startCol), other->stringData + size_v(startCol), size_v(compareLength)); // todo m17n
484  if (result == 0 && stringLength < colLength) {
485  if (clength > other->clength) {
486  result = 1;
487  }
488  else if (clength < other->clength) {
489  result = -1;
490  }
491  }
492  }
493  else {
494  if (clength == other->clength) {
495  result = 0;
496  }
497  else {
498  result = clength < other->clength ? -1 : 1;
499  }
500  }
501  return result;
502  }
503 
504 
505  static RexxString *newString(const char *, sizeB_t bl, sizeC_t cl=-1);
506  static RexxString *rawString(sizeB_t bl, sizeC_t cl=-1);
507  static RexxString *newUpperString(const char *, stringsizeB_t bl, stringsizeC_t cl=-1);
508  static RexxString *newString(double d);
509  static RexxString *newString(double d, size_t precision);
510  static RexxString *newProxy(const char *);
511  // NB: newRexx() cannot be static and exported as an ooRexx method.
512  RexxString *newRexx(RexxObject **, size_t, size_t); // in behaviour
514 
515  static void createInstance();
517 
518  protected:
519 
520  HashCode hashValue; // stored has value
521  sizeC_t clength; /* string length in characters */
522  sizeB_t blength; /* string length in bytes */
523  RexxNumberString *NumberString; /* lookaside information */
524  size_t Attributes; /* string attributes */
525  char stringData[4]; /* Start of the string data part */
526  };
527 
528 
529 // some handy functions for doing cstring/RexxString manipulations
530 
531  inline void * rmemcpy(void *t, RexxString *s, sizeB_t blen) // todo m17n : blen or clen ?
532  {
533  return memcpy(t, s->getStringData(), blen);
534  }
535 
536  inline int rmemcmp(const void *t, RexxString *s, sizeB_t blen) // todo m17n : blen or clen ?
537  {
538  return memcmp(t, s->getStringData(), blen);
539  }
540 
541  inline char * rstrcpy(char *t, RexxString *s)
542  {
543  return strcpy(t, s->getStringData());
544  }
545 
546  inline char * rstrcat(char *t, RexxString *s)
547  {
548  return strcat(t, s->getStringData());
549  }
550 
551  inline int rstrcmp(const char *t, RexxString *s)
552  {
553  return strcmp(t, s->getStringData());
554  }
555 
556  inline int rsnprintf(RexxString *s, const char *format, ...)
557  {
558  va_list args;
559  va_start(args, format);
560  int n = Utilities::vsnprintf(s->getWritableData(), size_v(s->getBLength()), format, args);
561  va_end(args);
562  s->finish(n >= 0 ? n : 0);
563  return n;
564  }
565 
566 // String creation inline functions
567 
568 inline RexxString *new_string(const char *s, stringsizeB_t bl, sizeC_t cl=-1)
569 {
570  return RexxString::newString(s, bl, cl);
571 }
572 
574 {
575  return RexxString::rawString(bl, cl);
576 }
577 
578 inline RexxString *new_string(double d)
579 {
580  return RexxString::newString(d);
581 }
582 
583 inline RexxString *new_string(double d, size_t p)
584 {
585  return RexxString::newString(d, p);
586 }
587 
588 
589 inline RexxString *new_string(const char *string)
590 {
591  return new_string(string, strlen(string), -1);
592 }
593 
594 inline RexxString *new_string(char cc)
595 {
596  return new_string(&cc, 1, 1);
597 }
598 
600 {
601  return new_string(r.strptr, r.strlength, -1);
602 }
603 
605 {
606  return new_string(r.strptr, r.strlength, -1);
607 }
608 
609 inline RexxString *new_proxy(const char *name)
610 {
611  return RexxString::newProxy(name);
612 }
613 
614 inline RexxString *new_upper_string(const char *s, stringsizeB_t bl, stringsizeC_t cl=-1)
615 {
616  return RexxString::newUpperString(s, bl, cl);
617 }
618 
619 inline RexxString *new_upper_string(const char *string)
620 {
621  return new_upper_string(string, strlen(string), -1);
622 }
623 
624 
625 // A RexxText is a RexxString by delegation, not by inheritance (don't inherit from RexxString)
626 class RexxText : public RexxObject
627 {
628 public:
629  inline void *operator new(size_t, void *ptr) { return ptr; }
630  inline void operator delete(void *, void *) { ; }
631  void *operator new(size_t);
632  inline void operator delete(void *) { ; }
633 
634  void live(size_t);
635  void liveGeneral(int reason);
636  void flatten(RexxEnvelope*);
637 
638  inline RexxText(RESTORETYPE restoreType) { ; };
639 
640  static void createInstance();
642 };
643 
644 #endif
RESTORETYPE
Definition: ObjectClass.hpp:80
RexxObject *(RexxObject::* PCPPM)()
size_t HashCode
Definition: ObjectClass.hpp:77
#define OREF_NULL
Definition: RexxCore.h:60
void * rmemcpy(void *t, RexxString *s, sizeB_t blen)
#define STRING_NOLOWER
Definition: StringClass.hpp:63
int rmemcmp(const void *t, RexxString *s, sizeB_t blen)
char * rstrcat(char *t, RexxString *s)
#define STRING_ISASCII
Definition: StringClass.hpp:66
#define STRING_NONNUMERIC
Definition: StringClass.hpp:64
char * rstrcpy(char *t, RexxString *s)
#define STRING_HASLOWER
Definition: StringClass.hpp:62
#define STRING_ISASCII_CHECKED
Definition: StringClass.hpp:65
RexxString * new_proxy(const char *name)
RexxString * new_string(const char *s, stringsizeB_t bl, sizeC_t cl=-1)
char IntToHexDigit(int n)
RexxString * raw_string(stringsizeB_t bl, stringsizeC_t cl=-1)
int rstrcmp(const char *t, RexxString *s)
RexxString * new_upper_string(const char *s, stringsizeB_t bl, stringsizeC_t cl=-1)
int rsnprintf(RexxString *s, const char *format,...)
RexxMessage * start(RexxObject **, size_t, size_t)
RexxObject * makeArrayRexx()
RexxString * stringValue()
RexxString * extractC(sizeC_t offset, sizeC_t sublength)
bool numberValue(wholenumber_t &result, size_t precision)
RexxInteger * isLessOrEqual(RexxObject *)
bool truthValue(int)
RexxArray * subWords(RexxInteger *, RexxInteger *)
RexxInteger * isLessThan(RexxObject *)
RexxString * concatRexx(RexxObject *)
static void createInstance()
Definition: StringClass.cpp:67
void setIsASCIIChecked()
RexxInteger * strictEqual(RexxObject *)
static RexxString * newString(const char *, sizeB_t bl, sizeC_t cl=-1)
RexxString * c2x()
RexxInteger * caselessEquals(RexxString *other)
static RexxString * newProxy(const char *)
RexxString * extractB(sizeB_t offset, sizeB_t sublength)
RexxObject * trunc(RexxInteger *decimals)
bool hasLower()
RexxString * changeStr(RexxString *, RexxString *, RexxInteger *)
RexxInteger * caselessLastPosRexx(RexxString *, RexxInteger *, RexxInteger *)
void toRxstring(CONSTRXSTRING &r)
RexxObject * xorOp(RexxObject *)
RexxString * translate(RexxString *, RexxString *, RexxString *, RexxInteger *, RexxInteger *)
RexxObject * operatorNot(RexxObject *)
RexxObject * Min(RexxObject **args, size_t argCount, size_t named_argCount)
RexxString * bitOr(RexxString *, RexxString *)
bool primitiveCaselessIsEqual(RexxObject *)
char stringData[4]
bool strCaselessCompare(const char *s)
RexxInteger * primitiveCompareTo(RexxString *other, stringsizeC_t start, stringsizeC_t len)
RexxInteger * strictGreaterThan(RexxObject *)
RexxObject * evaluate(RexxActivation *, RexxExpressionStack *)
RexxString * delstr(RexxInteger *, RexxInteger *)
RexxString * upperRexx(RexxInteger *, RexxInteger *)
int sortCompare(RexxString *other, sizeC_t startCol, sizeC_t colLength)
bool upperOnly()
HashCode getObjectHashCode()
bool checkIsASCII()
RexxString * bitAnd(RexxString *, RexxString *)
RexxInteger * wordIndex(RexxInteger *)
RexxInteger * notEqual(RexxObject *)
RexxInteger * strictLessOrEqual(RexxObject *)
const char * caselessLastPos(const char *needle, sizeB_t needleLen, const char *haystack, sizeB_t haystackLen)
RexxInteger * primitiveCaselessCompareTo(RexxString *other, stringsizeC_t start, stringsizeC_t len)
RexxNumberString * createNumberString()
RexxString * overlay(RexxString *, RexxInteger *, RexxInteger *, RexxString *)
bool isASCII()
RexxObject * lengthRexx()
RexxInteger * abbrev(RexxString *, RexxInteger *)
RexxNumberString * fastNumberString()
RexxObject * format(RexxObject *Integers, RexxObject *Decimals, RexxObject *MathExp, RexxObject *ExpTrigger)
bool doubleValue(double &result)
void toRxstring(RXSTRING &r)
void liveGeneral(int reason)
RexxString * b2x()
RexxInteger * caselessMatchChar(RexxInteger *position_, RexxString *matchSet)
void setBLength(sizeB_t l)
RexxString * makeString()
RexxString * subWord(RexxInteger *, RexxInteger *)
RexxObject * logicalOperation(RexxObject *, RexxObject *, unsigned int)
const char * getStringData()
RexxInteger * verify(RexxString *, RexxString *, RexxInteger *, RexxInteger *)
RexxInteger * caselessMatch(RexxInteger *start_, RexxString *other, RexxInteger *offset_, RexxInteger *len_)
RexxString * caselessChangeStr(RexxString *, RexxString *, RexxInteger *)
void setHasLower()
RexxString * space(RexxInteger *, RexxString *)
RexxString * encodeBase64()
RexxInteger * caselessPosRexx(RexxString *, RexxInteger *, RexxInteger *)
RexxObject * integerDivide(RexxObject *right)
void setNumberString(RexxObject *)
bool primitiveMatch(stringsizeC_t start, RexxString *other, stringsizeC_t offset, stringsizeC_t len)
RexxObject * remainder(RexxObject *right)
RexxString * d2x(RexxInteger *)
RexxObject * Max(RexxObject **args, size_t argCount, size_t named_argCount)
RexxInteger * integerValue(size_t precision)
RexxObject * ceiling()
RexxInteger * match(RexxInteger *start_, RexxString *other, RexxInteger *offset_, RexxInteger *len_)
RexxString * concatBlank(RexxObject *)
RexxInteger * caselessCountStrRexx(RexxString *)
RexxNumberString * numberString()
size_t Attributes
void setCLength(sizeC_t l)
RexxString * d2c(RexxInteger *)
RexxInteger * lastPosRexx(RexxString *, RexxInteger *, RexxInteger *)
bool isASCIIChecked()
RexxString * x2dC2d(RexxInteger *, bool)
RexxInteger * compareToRexx(RexxString *other, RexxInteger *start_, RexxInteger *len_)
RexxObject * getRealValue(RexxActivation *)
RexxInteger * compare(RexxString *, RexxString *)
char putCharB(sizeB_t p, char c)
bool primitiveIsEqual(RexxObject *)
RexxObject * plus(RexxObject *right)
int sortCaselessCompare(RexxString *other)
bool primitiveCaselessMatch(stringsizeC_t start, RexxString *other, stringsizeC_t offset, stringsizeC_t len)
RexxInteger * caselessCompare(RexxString *, RexxString *)
RexxInteger * strictLessThan(RexxObject *)
RexxInteger * strictGreaterOrEqual(RexxObject *)
bool memCompare(RexxString *other)
sizeC_t caselessPos(RexxString *, sizeC_t)
RexxString * extract(size_t offset, size_t sublength)
RexxString * bitXor(RexxString *, RexxString *)
char * getWritableData()
RexxString * lower()
RexxString * word(RexxInteger *)
char getCharB(sizeB_t p)
void flatten(RexxEnvelope *envelope)
RexxString * x2d(RexxInteger *)
RexxString * left(RexxInteger *, RexxString *)
RexxInteger * words()
RexxInteger * matchChar(RexxInteger *position_, RexxString *matchSet)
RexxObject * notOp()
bool memCompare(const char *s, sizeB_t l)
void memCopy(char *s)
RexxInteger * equal(RexxObject *)
virtual HashCode hash()
Definition: StringClass.cpp:73
RexxObject * multiply(RexxObject *right)
RexxString * subchar(RexxInteger *)
RexxString * substr(RexxInteger *, RexxInteger *, RexxString *)
RexxString * replaceAt(RexxString *, RexxInteger *, RexxInteger *, RexxString *)
RexxString * concatWithCstring(const char *)
RexxObject * dataType(RexxString *)
static RexxClass * classInstance
virtual bool logicalValue(logical_t &)
RexxObject * andOp(RexxObject *)
size_t caselessCountStr(RexxString *)
bool isEqual(RexxObject *)
wholenumber_t comp(RexxObject *, RexxString *alternativeOperator=OREF_NULL, RexxInteger **alternativeOperatorResultPtr=NULL)
virtual HashCode getHashValue()
sizeC_t lastPos(RexxString *needle, sizeC_t start)
RexxInteger * caselessWordPos(RexxString *, RexxInteger *)
RexxString * concat(RexxString *)
RexxString * concatWith(RexxString *, char)
bool checkLower()
static RexxString * newUpperString(const char *, stringsizeB_t bl, stringsizeC_t cl=-1)
RexxString * c2d(RexxInteger *)
RexxObject * getValue(RexxActivation *)
RexxInteger * caselessCompareToRexx(RexxString *other, RexxInteger *start_, RexxInteger *len_)
bool endsWith(codepoint_t c)
sizeC_t pos(RexxString *, sizeC_t)
RexxObject * round()
void set(sizeB_t s, int c, sizeB_t l)
RexxInteger * posRexx(RexxString *, RexxInteger *, RexxInteger *)
RexxString * stringTrace()
RexxInteger * wordLength(RexxInteger *)
RexxString * concatToCstring(const char *)
sizeC_t getCLength()
wholenumber_t compareTo(RexxObject *)
void put(sizeB_t s, RexxString *o)
RexxNumberString * NumberString
RexxString * copies(RexxInteger *)
RexxString * right(RexxInteger *, RexxString *)
sizeC_t caselessLastPos(RexxString *needle, sizeC_t start)
bool strCompare(const char *s)
HashCode getStringHash()
RexxString * x2b()
void copyToRxstring(RXSTRING &r)
void put(sizeB_t s, const void *b, sizeB_t l)
void setIsASCII()
void setNonNumeric()
RexxString * x2c()
RexxString * reverse()
RexxObject * isInteger()
codepoint_t getCharC(sizeC_t p)
sizeB_t copyData(sizeB_t, char *, sizeB_t)
RexxInteger * isASCIIRexx()
RexxInteger * countStrRexx(RexxString *)
bool nonNumeric()
RexxString * upper()
void live(size_t)
int sortCaselessCompare(RexxString *other, sizeC_t startCol, sizeC_t colLength)
RexxInteger * wordPos(RexxString *, RexxInteger *)
RexxObject * floor()
RexxInteger * caselessAbbrev(RexxString *, RexxInteger *)
RexxInteger * isGreaterOrEqual(RexxObject *)
sizeC_t clength
RexxObject * orOp(RexxObject *)
RexxString * newRexx(RexxObject **, size_t, size_t)
HashCode hashValue
RexxObject * divide(RexxObject *right)
int sortCompare(RexxString *other)
static RexxString * rawString(sizeB_t bl, sizeC_t cl=-1)
RexxObject * unflatten(RexxEnvelope *)
RexxString * insert(RexxString *, RexxInteger *, RexxInteger *, RexxString *)
RexxString * strip(RexxString *, RexxString *)
void finish(stringsizeB_t bl, sizeC_t cl=-1)
RexxArray * makeArray()
RexxString * delWord(RexxInteger *, RexxInteger *)
RexxInteger * equals(RexxString *other)
sizeB_t getBLength()
RexxObject * abs()
void setUpperOnly()
RexxInteger * isGreaterThan(RexxObject *)
RexxString(RESTORETYPE restoreType)
wholenumber_t strictComp(RexxObject *, RexxString *alternativeOperator=NULL, RexxInteger **alternativeOperatorResultPtr=NULL)
sizeB_t blength
RexxObject * power(RexxObject *right)
RexxString * decodeBase64()
RexxString * lowerRexx(RexxInteger *, RexxInteger *)
bool unsignedNumberValue(uwholenumber_t &result, size_t precision)
static PCPPM operatorMethods[]
RexxString * primitiveMakeString()
RexxInteger * strictNotEqual(RexxObject *)
RexxString * center(RexxInteger *, RexxString *)
RexxObject * sign()
RexxObject * minus(RexxObject *right)
void copyIntoTail(RexxCompoundTail *buffer)
void live(size_t)
void liveGeneral(int reason)
static RexxClass * classInstance
void flatten(RexxEnvelope *)
RexxText(RESTORETYPE restoreType)
static void createInstance()
static int caselessCompare(const char *, const char *, sizeB_t)
Definition: StringUtil.cpp:580
static int strCaselessCompare(const char *opt1, const char *opt2)
Definition: Utilities.cpp:82
static int vsnprintf(char *buffer, size_t count, const char *format, va_list args)
stringsize_t stringsizeC_t
Definition: rexx.h:241
stringsize_t stringsizeB_t
Definition: rexx.h:247
stringsizeC_t sizeC_t
Definition: rexx.h:242
size_t logical_t
Definition: rexx.h:231
ssize_t codepoint_t
Definition: rexx.h:232
#define stringsize_v(X)
Definition: rexx.h:238
ssize_t wholenumber_t
Definition: rexx.h:230
#define size_v(X)
Definition: rexx.h:237
stringsizeB_t sizeB_t
Definition: rexx.h:248
#define sizeC_v(X)
Definition: rexx.h:244
size_t uwholenumber_t
Definition: rexx.h:229
const char * strptr
Definition: rexx.h:163
size_t strlength
Definition: rexx.h:162
size_t strlength
Definition: rexx.h:157
char * strptr
Definition: rexx.h:158