ooRexx  4.2.0-source
About: ooRexx (Open Object Rexx) is a free implementation of Object Rexx. Object Rexx is an enhancement of the classic Rexx interpreter; a full-featured programming language with a human-oriented syntax.
  Fossies Dox: ooRexx-4.2.0-source.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

Utilities.cpp
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 /* Utility Functions */
42 /* */
43 /****************************************************************************/
44 
45 #include <stdarg.h>
46 #include <stdlib.h>
47 #include <string.h>
48 #include <ctype.h>
49 #include <sys/types.h>
50 #include "Utilities.hpp"
51 
53  const char *string, /* search string */
54  const char *set, /* reference set */
55  size_t length ) /* size of string */
56 /*********************************************************************/
57 /* Function: Find first occurence of set member in memory */
58 /*********************************************************************/
59 {
60  while (length-- > 0)
61  { /* search through string */
62 
63  if (strchr(set, *string))
64  { /* find a match in ref set? */
65  return string;
66  }
67  string++; /* step the pointer */
68  }
69  return NULL; /* return matched position */
70 }
71 
72 
82 int Utilities::strCaselessCompare(const char *op1, const char *op2)
83 {
84  while (tolower(*op1) == tolower(*op2))
85  {
86  if (*op1 == 0)
87  {
88  return 0;
89  }
90  op1++;
91  op2++;
92  }
93 
94  return(tolower(*op1) - tolower(*op2));
95 }
96 
107 int Utilities::memicmp(const void *mem1, const void *mem2, size_t len)
108 {
109  const char *op1 = (const char *)mem1;
110  const char *op2 = (const char *)mem2;
111  while(len != 0)
112  {
113  if (tolower(*op1) != tolower(*op2))
114  {
115  return tolower(*op1) - tolower(*op2);
116 
117  }
118  op1++;
119  op2++;
120  len--;
121  }
122  return 0;
123 }
124 
132 void Utilities::strupper(char *str)
133 {
134  while (*str)
135  {
136  *str = toupper(*str);
137  str++;
138  }
139 
140  return;
141 }
142 
143 
151 void Utilities::strlower(char *str)
152 {
153  while (*str)
154  {
155  *str = tolower(*str);
156  str++;
157  }
158 
159  return;
160 }
161 
162 
172 const char *Utilities::strnchr(const char *data, size_t n, char ch)
173 {
174  const char *endPtr = data + n;
175  while (data < endPtr && *data != '\0')
176  {
177  if (*data == ch)
178  {
179  return data;
180  }
181  data++;
182  }
183  return NULL;
184 }
Utilities::strupper
static void strupper(char *str)
Definition: Utilities.cpp:132
Utilities::memicmp
static int memicmp(const void *opt1, const void *opt2, size_t len)
Definition: Utilities.cpp:107
Utilities::strlower
static void strlower(char *str)
Definition: Utilities.cpp:151
Utilities::strnchr
static const char * strnchr(const char *, size_t n, char ch)
Definition: Utilities.cpp:172
Utilities::locateCharacter
static const char * locateCharacter(const char *s, const char *set, size_t l)
Definition: Utilities.cpp:52
Utilities.hpp
Utilities::strCaselessCompare
static int strCaselessCompare(const char *opt1, const char *opt2)
Definition: Utilities.cpp:82