StringUtil.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 */
40 /* */
41 /* String Utilities shared between String class and MutableBuffer class */
42 /* */
43 /******************************************************************************/
44 #ifndef Included_StringUtil
45 #define Included_StringUtil
46 
47 class RexxInteger;
48 class RexxArray;
49 
51 {
52 public:
53  static RexxString *substr(const char *, size_t, RexxInteger *, RexxInteger *, RexxString *);
54  static RexxInteger *posRexx(const char *stringData, size_t length, RexxString *needle, RexxInteger *pstart, RexxInteger *range);
55  static size_t pos(const char *stringData, size_t haystack_length, RexxString *needle, size_t _start, size_t _range);
56  static size_t caselessPos(const char *stringData, size_t haystack_length, RexxString *needle, size_t _start, size_t _range);
57  static RexxInteger *lastPosRexx(const char *stringData, size_t haystackLen, RexxString *needle, RexxInteger *_start, RexxInteger *_range);
58  static size_t lastPos(const char *stringData, size_t hastackLen, RexxString *needle, size_t _start, size_t _range);
59  static const char *lastPos(const char *needle, size_t needleLen, const char *haystack, size_t haystackLen);
60  static RexxString *subchar(const char *stringData, size_t stringLength, RexxInteger *positionArg);
61  static RexxArray *makearray(const char *start, size_t length, RexxString *separator);
62  static RexxArray *makearray(RexxString *str, RexxString *separator);
63  static size_t caselessLastPos(const char *stringData, size_t haystackLen, RexxString *needle, size_t _start, size_t range);
64  static const char * caselessLastPos(const char *needle, size_t needleLen, const char *haystack, size_t haystackLen);
65  static int caselessCompare(const char *, const char *, size_t);
66  static int hexDigitToInt(char ch);
67  static char packByte(const char *String);
68  static void unpackNibble(int Val, char *p);
69  static char packNibble(const char *String);
70  static RexxString *packHex(const char *String, size_t StringLength);
71  static size_t chGetSm(char *Destination, const char *Source, size_t Length, size_t Count, const char *Set, size_t *ScannedSize);
72  static size_t validateSet(const char *String, size_t Length, const char *Set, int Modulus, bool Hex);
73  static char packByte2(const char *Byte);
74  static int valSet(const char *String, size_t Length, const char *Set, int Modulus, size_t *PackedSize );
75  static const char *memcpbrk(const char *String, const char *Set, size_t Length);
76  static RexxObject *dataType(RexxString *String, char Option );
77  static size_t wordCount(const char *String, size_t StringLength );
78  static void skipNonBlanks(const char **String, size_t *StringLength);
79  static void skipBlanks(const char **String, size_t *StringLength);
80  static size_t nextWord(const char **String, size_t *StringLength, const char **NextString );
81  static size_t countStr(const char *hayStack, size_t hayStackLength, RexxString *needle);
82  static size_t caselessCountStr(const char *hayStack, size_t hayStackLength, RexxString *needle);
83  static size_t memPos(const char *string, size_t length, char target);
84  static RexxInteger *verify(const char *data, size_t stringLen, RexxString *ref, RexxString *option, RexxInteger *_start, RexxInteger *range);
85  static RexxString *subWord(const char *data, size_t length, RexxInteger *position, RexxInteger *plength);
86  static RexxArray *subWords(const char *data, size_t length, RexxInteger *position, RexxInteger *plength);
87  static RexxString *word(const char *data, size_t length, RexxInteger *position);
88  static RexxInteger *wordIndex(const char *data, size_t length, RexxInteger *position);
89  static RexxInteger *wordLength(const char *data, size_t length, RexxInteger *position);
90  static RexxInteger *wordPos(const char *data, size_t length, RexxString *phrase, RexxInteger *pstart);
91  static RexxInteger *caselessWordPos(const char *data, size_t length, RexxString *phrase, RexxInteger *pstart);
92  static RexxArray *words(const char *data, size_t length);
93  static const char *locateSeparator(const char *start, const char *end, const char *sepData, size_t sepLength);
94  static bool checkIsASCII(const char *s, size_t length);
95 
96  static inline bool matchCharacter(char ch, const char *charSet, size_t len)
97  {
98  while (len-- > 0)
99  {
100  if (ch == *charSet++)
101  {
102  return true;
103  }
104  }
105  return false;
106  }
107 };
108 
109 #endif
110 
size_t RexxEntry StringLength(RexxThreadContext *c, RexxStringObject s)
static void unpackNibble(int Val, char *p)
Definition: StringUtil.cpp:949
static size_t validateSet(const char *String, size_t Length, const char *Set, int Modulus, bool Hex)
Definition: StringUtil.cpp:726
static size_t pos(const char *stringData, size_t haystack_length, RexxString *needle, size_t _start, size_t _range)
Definition: StringUtil.cpp:155
static RexxString * packHex(const char *String, size_t StringLength)
Definition: StringUtil.cpp:875
static const char * memcpbrk(const char *String, const char *Set, size_t Length)
Definition: StringUtil.cpp:967
static char packByte2(const char *Byte)
Definition: StringUtil.cpp:693
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)
Definition: StringUtil.cpp:360
static size_t wordCount(const char *String, size_t StringLength)
static char packNibble(const char *String)
Definition: StringUtil.cpp:668
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)
Definition: StringUtil.cpp:580
static RexxInteger * lastPosRexx(const char *stringData, size_t haystackLen, RexxString *needle, RexxInteger *_start, RexxInteger *_range)
Definition: StringUtil.cpp:255
static size_t caselessPos(const char *stringData, size_t haystack_length, RexxString *needle, size_t _start, size_t _range)
Definition: StringUtil.cpp:205
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)
Definition: StringUtil.hpp:96
static RexxInteger * wordLength(const char *data, size_t length, RexxInteger *position)
static RexxArray * makearray(const char *start, size_t length, RexxString *separator)
Definition: StringUtil.cpp:493
static int hexDigitToInt(char ch)
Definition: StringUtil.cpp:618
static size_t chGetSm(char *Destination, const char *Source, size_t Length, size_t Count, const char *Set, size_t *ScannedSize)
Definition: StringUtil.cpp:835
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)
Definition: StringUtil.cpp:467
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)
Definition: StringUtil.cpp:442
static char packByte(const char *String)
Definition: StringUtil.cpp:644
static RexxString * substr(const char *, size_t, RexxInteger *, RexxInteger *, RexxString *)
Definition: StringUtil.cpp:66
static size_t lastPos(const char *stringData, size_t hastackLen, RexxString *needle, size_t _start, size_t _range)
Definition: StringUtil.cpp:278
static RexxInteger * posRexx(const char *stringData, size_t length, RexxString *needle, RexxInteger *pstart, RexxInteger *range)
Definition: StringUtil.cpp:130
static RexxArray * words(const char *data, size_t length)