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