| 1 |
/* do not edit automatically generated by mc from StrCase. */ |
| 2 |
/* StrCase.mod provides procedure to convert between text case. |
| 3 |
|
| 4 |
Copyright (C) 2001-2025 Free Software Foundation, Inc. |
| 5 |
Contributed by Gaius Mulley <[email protected]>. |
| 6 |
|
| 7 |
This file is part of GNU Modula-2. |
| 8 |
|
| 9 |
GNU Modula-2 is free software; you can redistribute it and/or modify |
| 10 |
it under the terms of the GNU General Public License as published by |
| 11 |
the Free Software Foundation; either version 3, or (at your option) |
| 12 |
any later version. |
| 13 |
|
| 14 |
GNU Modula-2 is distributed in the hope that it will be useful, but |
| 15 |
WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 |
General Public License for more details. |
| 18 |
|
| 19 |
Under Section 7 of GPL version 3, you are granted additional |
| 20 |
permissions described in the GCC Runtime Library Exception, version |
| 21 |
3.1, as published by the Free Software Foundation. |
| 22 |
|
| 23 |
You should have received a copy of the GNU General Public License and |
| 24 |
a copy of the GCC Runtime Library Exception along with this program; |
| 25 |
see the files COPYING3 and COPYING.RUNTIME respectively. If not, see |
| 26 |
<http://www.gnu.org/licenses/>. */ |
| 27 |
|
| 28 |
#include "config.h" |
| 29 |
#include "system.h" |
| 30 |
#include <stdbool.h> |
| 31 |
# if !defined (PROC_D) |
| 32 |
# define PROC_D |
| 33 |
typedef void (*PROC_t) (void); |
| 34 |
typedef struct { PROC_t proc; } PROC; |
| 35 |
# endif |
| 36 |
|
| 37 |
#define _StrCase_C |
| 38 |
|
| 39 |
#include "GStrCase.h" |
| 40 |
# include "GASCII.h" |
| 41 |
# include "GStrLib.h" |
| 42 |
|
| 43 |
|
| 44 |
/* |
| 45 |
StrToUpperCase - converts string, a, to uppercase returning the |
| 46 |
result in, b. |
| 47 |
*/ |
| 48 |
|
| 49 |
extern "C" void StrCase_StrToUpperCase (const char *a_, unsigned int _a_high, char *b, unsigned int _b_high); |
| 50 |
|
| 51 |
/* |
| 52 |
StrToLowerCase - converts string, a, to lowercase returning the |
| 53 |
result in, b. |
| 54 |
*/ |
| 55 |
|
| 56 |
extern "C" void StrCase_StrToLowerCase (const char *a_, unsigned int _a_high, char *b, unsigned int _b_high); |
| 57 |
|
| 58 |
/* |
| 59 |
Cap - converts a lower case character into a capital character. |
| 60 |
If the character is not a lower case character 'a'..'z' |
| 61 |
then the character is simply returned unaltered. |
| 62 |
*/ |
| 63 |
|
| 64 |
extern "C" char StrCase_Cap (char ch); |
| 65 |
|
| 66 |
/* |
| 67 |
Lower - converts an upper case character into a lower case character. |
| 68 |
If the character is not an upper case character 'A'..'Z' |
| 69 |
then the character is simply returned unaltered. |
| 70 |
*/ |
| 71 |
|
| 72 |
extern "C" char StrCase_Lower (char ch); |
| 73 |
|
| 74 |
|
| 75 |
/* |
| 76 |
StrToUpperCase - converts string, a, to uppercase returning the |
| 77 |
result in, b. |
| 78 |
*/ |
| 79 |
|
| 80 |
extern "C" void StrCase_StrToUpperCase (const char *a_, unsigned int _a_high, char *b, unsigned int _b_high) |
| 81 |
{ |
| 82 |
unsigned int higha; |
| 83 |
unsigned int highb; |
| 84 |
unsigned int i; |
| 85 |
char a[_a_high+1]; |
| 86 |
|
| 87 |
/* make a local copy of each unbounded array. */ |
| 88 |
memcpy (a, a_, _a_high+1); |
| 89 |
|
| 90 |
higha = StrLib_StrLen ((const char *) a, _a_high); |
| 91 |
highb = _b_high; |
| 92 |
i = 0; |
| 93 |
while (((i < higha) && (a[i] != ASCII_nul)) && (i < highb)) |
| 94 |
{ |
| 95 |
const_cast<char *>(b)[i] = StrCase_Cap (a[i]); |
| 96 |
i += 1; |
| 97 |
} |
| 98 |
if (i < highb) |
| 99 |
{ |
| 100 |
const_cast<char *>(b)[i] = ASCII_nul; |
| 101 |
} |
| 102 |
} |
| 103 |
|
| 104 |
|
| 105 |
/* |
| 106 |
StrToLowerCase - converts string, a, to lowercase returning the |
| 107 |
result in, b. |
| 108 |
*/ |
| 109 |
|
| 110 |
extern "C" void StrCase_StrToLowerCase (const char *a_, unsigned int _a_high, char *b, unsigned int _b_high) |
| 111 |
{ |
| 112 |
unsigned int higha; |
| 113 |
unsigned int highb; |
| 114 |
unsigned int i; |
| 115 |
char a[_a_high+1]; |
| 116 |
|
| 117 |
/* make a local copy of each unbounded array. */ |
| 118 |
memcpy (a, a_, _a_high+1); |
| 119 |
|
| 120 |
higha = StrLib_StrLen ((const char *) a, _a_high); |
| 121 |
highb = _b_high; |
| 122 |
i = 0; |
| 123 |
while (((i < higha) && (a[i] != ASCII_nul)) && (i < highb)) |
| 124 |
{ |
| 125 |
const_cast<char *>(b)[i] = StrCase_Lower (a[i]); |
| 126 |
i += 1; |
| 127 |
} |
| 128 |
if (i < highb) |
| 129 |
{ |
| 130 |
const_cast<char *>(b)[i] = ASCII_nul; |
| 131 |
} |
| 132 |
} |
| 133 |
|
| 134 |
|
| 135 |
/* |
| 136 |
Cap - converts a lower case character into a capital character. |
| 137 |
If the character is not a lower case character 'a'..'z' |
| 138 |
then the character is simply returned unaltered. |
| 139 |
*/ |
| 140 |
|
| 141 |
extern "C" char StrCase_Cap (char ch) |
| 142 |
{ |
| 143 |
if ((ch >= 'a') && (ch <= 'z')) |
| 144 |
{ |
| 145 |
ch = ((char) (( ((unsigned int) (ch))- ((unsigned int) ('a')))+ ((unsigned int) ('A')))); |
| 146 |
} |
| 147 |
return ch; |
| 148 |
/* static analysis guarentees a RETURN statement will be used before here. */ |
| 149 |
__builtin_unreachable (); |
| 150 |
} |
| 151 |
|
| 152 |
|
| 153 |
/* |
| 154 |
Lower - converts an upper case character into a lower case character. |
| 155 |
If the character is not an upper case character 'A'..'Z' |
| 156 |
then the character is simply returned unaltered. |
| 157 |
*/ |
| 158 |
|
| 159 |
extern "C" char StrCase_Lower (char ch) |
| 160 |
{ |
| 161 |
if ((ch >= 'A') && (ch <= 'Z')) |
| 162 |
{ |
| 163 |
ch = ((char) (( ((unsigned int) (ch))- ((unsigned int) ('A')))+ ((unsigned int) ('a')))); |
| 164 |
} |
| 165 |
return ch; |
| 166 |
/* static analysis guarentees a RETURN statement will be used before here. */ |
| 167 |
__builtin_unreachable (); |
| 168 |
} |
| 169 |
|
| 170 |
extern "C" void _M2_StrCase_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[]) |
| 171 |
{ |
| 172 |
} |
| 173 |
|
| 174 |
extern "C" void _M2_StrCase_fini (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[]) |
| 175 |
{ |
| 176 |
} |