73 if (stringLength >= position)
76 length = stringLength - position;
86 return OREF_NULLSTRING;
89 size_t substrLength = 0;
94 if (position > stringLength)
102 padCount = length - substrLength;
105 if (substrLength != 0)
108 retval->
put(0,
string + position, substrLength);
113 retval->
set(substrLength, (
int)padChar, padCount);
139 size_t result =
pos(stringData, length, needle, _start - 1, _range);
158 size_t needle_length = needle->
getLength();
166 if (_start >= haystack_length || needle_length > _range || needle_length == 0)
172 const char *haypointer = stringData + _start;
174 size_t location = _start + 1;
176 size_t count = _range - needle_length + 1;
182 if (memcmp(haypointer, needlepointer, needle_length) == 0)
208 size_t needle_length = needle->
getLength();
216 if (_start > haystack_length || needle_length > _range || needle_length == 0)
222 const char *haypointer = stringData + _start;
224 size_t location = _start + 1;
226 size_t count = _range - needle_length + 1;
262 size_t result =
lastPos(stringData, haystackLen, needle, startPos, range);
283 if (needleLen == 0 || haystackLen == 0 || needleLen > range)
293 const char *startPoint = stringData + haystackLen - range;
296 if (matchLocation == NULL)
302 return matchLocation - stringData + 1;
321 const char *
StringUtil::lastPos(
const char *needle,
size_t needleLen,
const char *haystack,
size_t haystackLen)
324 if (needleLen > haystackLen)
329 haystack = haystack + haystackLen - needleLen;
331 size_t count = haystackLen - needleLen + 1;
336 if (memcmp(haystack, needle, needleLen) == 0)
365 if (needleLen == 0 || haystackLen == 0 || needleLen > range)
375 const char *startPoint = stringData + haystackLen - range;
378 if (matchLocation == NULL)
384 return matchLocation - stringData + 1;
406 if (needleLen > haystackLen)
411 haystack = haystack + haystackLen - needleLen;
413 size_t count = haystackLen - needleLen + 1;
448 if (position >= stringLength)
450 return OREF_NULLSTRING;
472 if (memcmp(start, sepData, sepLength) == 0)
495 const char *sepData =
"\n";
518 for (
size_t i = 0; i < length; i++, start++)
529 const char *stringEnd = start + length;
532 const char *end = start + length - sepSize + 1;
542 size_t stringLen = tmp - start;
545 if (checkCR && *(tmp - 1) ==
'\r')
551 start = tmp + sepSize;
554 if (start < stringEnd)
556 size_t stringLen = stringEnd - start;
583 if (!memcmp(string1, string2, length))
588 while (length-- != 0)
591 if (toupper(*string1) != toupper(*string2))
594 if (toupper(*string1) < toupper(*string2))
628 Retval = toupper(ch) -
'A' + 10;
647 for (
int i = 0; i < 8; i++)
649 if (String[i] ==
'1')
651 Result |= (1<<(7-i));
674 memcpy(Buf+4, String, 4);
676 return "0123456789ABCDEF"[i];
703 return((Nibble1 << 4) | Nibble2);
731 const char *SpaceLocation = NULL;
754 for (; Length != 0; Length--)
758 if (c !=
'\0' && strchr(Set, c) != NULL)
766 SpaceLocation = Current;
770 Residue = (Count % Modulus);
774 else if (Residue != (Count % Modulus))
804 if ((c ==
ch_SPACE || c ==
ch_TAB) || (SpaceFound && ((Count % Modulus) != Residue)))
835 size_t StringUtil::chGetSm(
char *Destination,
const char *Source,
size_t Length,
size_t Count,
const char *Set,
size_t *ScannedSize)
846 for (; Length != 0; Length--)
851 if (c !=
'\0' && strchr(Set, c) != NULL)
854 if (++Found == Count)
860 *ScannedSize = Scanned;
920 Retval = OREF_NULLSTRING;
923 if (Retval != OREF_NULLSTRING)
930 bool messageUnderstood = Retval->
messageSend(OREF_SETENCODING, args, 1, 0, result,
false);
951 p[0] = (Val & 0x08) != 0 ?
'1':
'0';
952 p[1] = (Val & 0x04) != 0 ?
'1':
'0';
953 p[2] = (Val & 0x02) != 0 ?
'1':
'0';
954 p[3] = (Val & 0x01) != 0 ?
'1':
'0';
972 while (Length-- != 0)
975 if (*String ==
'\0' || !strchr(Set, *String))
1005 int StringUtil::valSet(
const char *String,
size_t Length,
const char *Set,
int Modulus,
size_t *PackedSize )
1009 const char *Current;
1015 if (*String !=
' ' && *String !=
'\t')
1022 for (; Length != 0; Length--)
1026 if (c !=
'\0' && strchr(Set, c) != NULL)
1032 if (c ==
' ' || c ==
'\t')
1037 Residue = (Count % Modulus);
1041 else if (Residue != (Count % Modulus))
1056 if (c ==
' ' || c ==
'\t')
1060 else if (SpaceFound && (Count % Modulus) != Residue)
1066 *PackedSize = Count;
1093 Option = toupper(Option);
1210 if (Len != 1 || (*Scanp !=
'1' && *Scanp !=
'0'))
1243 for (;Length != 0; Length--)
1245 if (*Scan !=
' ' && *Scan !=
'\t')
1271 for (;Length != 0; Length--)
1273 if (*Scan ==
' ' || *Scan ==
'\t')
1331 size_t WordStart = 0;
1339 *NextString = *String;
1363 size_t matchPos =
pos(hayStack, hayStackLength, needle, 0, hayStackLength);
1364 while (matchPos != 0)
1368 matchPos =
pos(hayStack, hayStackLength, needle, matchPos + needle->
getLength() - 1, hayStackLength);
1388 size_t matchPos =
caselessPos(hayStack, hayStackLength, needle, 0, hayStackLength);
1389 while (matchPos != 0)
1393 matchPos =
caselessPos(hayStack, hayStackLength, needle, matchPos + needle->
getLength() - 1, hayStackLength);
1408 for (
const char *scan =
string; length != 0; length--)
1411 if (*scan == target)
1413 return scan - string;
1450 if (startPos > stringLen)
1460 const char *current = data + startPos - 1;
1461 if (referenceLen == 0)
1478 while (stringRange-- != 0)
1491 while (stringRange-- != 0)
1525 if (length == 0 || count == 0)
1527 return OREF_NULLSTRING;
1529 const char *nextSite = NULL;
1530 const char *
word = data;
1543 return OREF_NULLSTRING;
1546 const char *wordStart =
word;
1547 const char *wordEnd =
word;
1557 return new_string(wordStart, wordEnd - wordStart);
1579 if (length == 0 || count == 0)
1584 const char *nextSite = NULL;
1585 const char *
word = data;
1605 const char *wordStart =
word;
1636 return OREF_NULLSTRING;
1638 const char *
word = data;
1639 const char *nextSite = NULL;
1653 return OREF_NULLSTRING;
1668 const char *
word = data;
1669 const char *nextSite = NULL;
1700 const char *
word = data;
1701 const char *nextSite = NULL;
1734 const char *
word = data;
1735 const char *nextSite = NULL;
1768 const char *haystack = data;
1778 if (needleWords > (haystackWords - count + 1) || needleWords == 0 || count > haystackWords)
1783 const char *nextHaystack;
1784 const char *nextNeedle;
1788 for (
stringsize_t i = count - 1; i && haystackWordLength != 0; i--)
1790 haystack = nextHaystack;
1792 haystackWordLength =
nextWord(&haystack, &haystackLength, &nextHaystack);
1795 stringsize_t searchCount = (haystackWords - needleWords - count) + 2;
1799 for (; searchCount; searchCount--)
1802 const char *needlePosition = needle;
1803 const char *haystackPosition = haystack;
1805 const char *nextHaystackPtr = nextHaystack;
1806 const char *nextNeedlePtr = nextNeedle;
1813 for (i = needleWords; i; i--)
1817 if (haystackWordLength != needleWordLength)
1824 if (memcmp(needlePosition, haystackPosition, needleWordLength) != 0)
1833 haystackPosition = nextHaystackPtr;
1834 needlePosition = nextNeedlePtr;
1836 haystackWordLength =
nextWord(&haystackPosition, &haystackScanLength, &nextHaystackPtr);
1838 needleWordLength =
nextWord(&needlePosition, &needleScanLength, &nextNeedlePtr);
1845 haystack = nextHaystack;
1847 haystackWordLength =
nextWord(&haystack, &haystackLength, &nextHaystack);
1874 const char *haystack = data;
1884 if (needleWords > (haystackWords - count + 1) || needleWords == 0 || count > haystackWords)
1889 const char *nextHaystack;
1890 const char *nextNeedle;
1894 for (
stringsize_t i = count - 1; i && haystackWordLength != 0; i--)
1896 haystack = nextHaystack;
1898 haystackWordLength =
nextWord(&haystack, &haystackLength, &nextHaystack);
1901 stringsize_t searchCount = (haystackWords - needleWords - count) + 2;
1905 for (; searchCount; searchCount--)
1908 const char *needlePosition = needle;
1909 const char *haystackPosition = haystack;
1911 const char *nextHaystackPtr = nextHaystack;
1912 const char *nextNeedlePtr = nextNeedle;
1919 for (i = needleWords; i; i--)
1923 if (haystackWordLength != needleWordLength)
1930 if (
caselessCompare(needlePosition, haystackPosition, needleWordLength))
1939 haystackPosition = nextHaystackPtr;
1940 needlePosition = nextNeedlePtr;
1942 haystackWordLength =
nextWord(&haystackPosition, &haystackScanLength, &nextHaystackPtr);
1944 needleWordLength =
nextWord(&needlePosition, &needleScanLength, &nextNeedlePtr);
1951 haystack = nextHaystack;
1953 haystackWordLength =
nextWord(&haystack, &haystackLength, &nextHaystack);
1976 const char *i2 = s + (length - 1) / 2;
1977 const char *i3 = i2;
1978 const char *i4 = s + length - 1;
1982 if ( (*i1++ | *i2-- | *i3++ | *i4--) & 0x80 )
return false;
1984 while (i1 <= i2 || i3 <= i4);
void reportException(wholenumber_t error)
RexxArray * new_array(size_t s)
RexxInteger * new_integer(wholenumber_t v)
codepoint_t optionalPadArgument(RexxObject *o, codepoint_t d, size_t p)
RexxString * stringArgument(RexxObject *object, RexxString *kind, size_t position)
size_t optionalLengthArgument(RexxObject *o, size_t d, size_t p)
char optionalOptionArgument(RexxObject *o, char d, size_t p)
size_t optionalPositionArgument(RexxObject *o, size_t d, size_t p)
#define Error_Incorrect_method_option
#define Error_Incorrect_method_invbin
#define Error_Incorrect_method_invhex
#define Error_Incorrect_method_binblank
#define Error_Incorrect_method_hexblank
#define DATATYPE_UPPERCASE
#define DATATYPE_LOWERCASE
RexxString * raw_string(stringsize_t l)
RexxString * new_string(const char *s, stringsize_t l)
#define DATATYPE_MIXEDCASE
#define STRING_COMPOUND_NAME
#define DATATYPE_ALPHANUMERIC
#define DATATYPE_WHOLE_NUMBER
#define DATATYPE_VARIABLE
#define STRING_BAD_VARIABLE
stringsize_t positionArgument(RexxObject *argument, size_t position)
size_t RexxEntry StringLength(RexxThreadContext *c, RexxStringObject s)
static const wholenumber_t MAX_WHOLENUMBER
static wholenumber_t minVal(wholenumber_t n1, wholenumber_t n2)
void put(RexxObject *eref, size_t pos)
size_t append(RexxObject *)
RexxNumberString * plus(RexxObject *)
bool messageSend(RexxString *, RexxObject **, size_t, size_t, ProtectedObject &, bool processUnknown=true, bool dynamicTarget=true)
void queue(RexxObject *obj)
bool numberValue(wholenumber_t &result, size_t precision)
const char * getStringData()
RexxNumberString * numberString()
void set(size_t s, int c, size_t l)
void put(size_t s, const void *b, size_t l)
static void unpackNibble(int Val, char *p)
static size_t validateSet(const char *String, size_t Length, const char *Set, int Modulus, bool Hex)
static size_t pos(const char *stringData, size_t haystack_length, RexxString *needle, size_t _start, size_t _range)
static RexxString * packHex(const char *String, size_t StringLength)
static const char * memcpbrk(const char *String, const char *Set, size_t Length)
static char packByte2(const char *Byte)
static RexxInteger * caselessWordPos(const char *data, size_t length, RexxString *phrase, RexxInteger *pstart)
static int valSet(const char *String, size_t Length, const char *Set, int Modulus, size_t *PackedSize)
static RexxInteger * wordIndex(const char *data, size_t length, RexxInteger *position)
static RexxArray * subWords(const char *data, size_t length, RexxInteger *position, RexxInteger *plength)
static RexxObject * dataType(RexxString *String, char Option)
static bool checkIsASCII(const char *s, size_t length)
static size_t memPos(const char *string, size_t length, char target)
static void skipBlanks(const char **String, size_t *StringLength)
static size_t caselessLastPos(const char *stringData, size_t haystackLen, RexxString *needle, size_t _start, size_t range)
static size_t wordCount(const char *String, size_t StringLength)
static char packNibble(const char *String)
static RexxString * subWord(const char *data, size_t length, RexxInteger *position, RexxInteger *plength)
static void skipNonBlanks(const char **String, size_t *StringLength)
static int caselessCompare(const char *, const char *, size_t)
static RexxInteger * lastPosRexx(const char *stringData, size_t haystackLen, RexxString *needle, RexxInteger *_start, RexxInteger *_range)
static size_t caselessPos(const char *stringData, size_t haystack_length, RexxString *needle, size_t _start, size_t _range)
static size_t nextWord(const char **String, size_t *StringLength, const char **NextString)
static RexxInteger * wordPos(const char *data, size_t length, RexxString *phrase, RexxInteger *pstart)
static bool matchCharacter(char ch, const char *charSet, size_t len)
static RexxInteger * wordLength(const char *data, size_t length, RexxInteger *position)
static RexxArray * makearray(const char *start, size_t length, RexxString *separator)
static int hexDigitToInt(char ch)
static size_t chGetSm(char *Destination, const char *Source, size_t Length, size_t Count, const char *Set, size_t *ScannedSize)
static size_t countStr(const char *hayStack, size_t hayStackLength, RexxString *needle)
static const char * locateSeparator(const char *start, const char *end, const char *sepData, size_t sepLength)
static size_t caselessCountStr(const char *hayStack, size_t hayStackLength, RexxString *needle)
static RexxInteger * verify(const char *data, size_t stringLen, RexxString *ref, RexxString *option, RexxInteger *_start, RexxInteger *range)
static RexxString * word(const char *data, size_t length, RexxInteger *position)
static RexxString * subchar(const char *stringData, size_t stringLength, RexxInteger *positionArg)
static char packByte(const char *String)
static RexxString * substr(const char *, size_t, RexxInteger *, RexxInteger *, RexxString *)
static size_t lastPos(const char *stringData, size_t hastackLen, RexxString *needle, size_t _start, size_t _range)
static RexxInteger * posRexx(const char *stringData, size_t length, RexxString *needle, RexxInteger *pstart, RexxInteger *range)
static RexxArray * words(const char *data, size_t length)