]>
Commit | Line | Data |
---|---|---|
1eee94d3 GM |
1 | /* do not edit automatically generated by mc from StrCase. */ |
2 | /* StrCase.mod provides procedure to convert between text case. | |
3 | ||
83ffe9cd | 4 | Copyright (C) 2001-2023 Free Software Foundation, Inc. |
1eee94d3 GM |
5 | Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>. |
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 | # if !defined (PROC_D) | |
29 | # define PROC_D | |
30 | typedef void (*PROC_t) (void); | |
31 | typedef struct { PROC_t proc; } PROC; | |
32 | # endif | |
33 | ||
34 | #include <string.h> | |
35 | #include <limits.h> | |
36 | #define _StrCase_H | |
37 | #define _StrCase_C | |
38 | ||
39 | # include "GASCII.h" | |
40 | # include "GStrLib.h" | |
41 | ||
42 | ||
43 | /* | |
44 | StrToUpperCase - converts string, a, to uppercase returning the | |
45 | result in, b. | |
46 | */ | |
47 | ||
48 | extern "C" void StrCase_StrToUpperCase (const char *a_, unsigned int _a_high, char *b, unsigned int _b_high); | |
49 | ||
50 | /* | |
51 | StrToLowerCase - converts string, a, to lowercase returning the | |
52 | result in, b. | |
53 | */ | |
54 | ||
55 | extern "C" void StrCase_StrToLowerCase (const char *a_, unsigned int _a_high, char *b, unsigned int _b_high); | |
56 | ||
57 | /* | |
58 | Cap - converts a lower case character into a capital character. | |
59 | If the character is not a lower case character 'a'..'z' | |
60 | then the character is simply returned unaltered. | |
61 | */ | |
62 | ||
63 | extern "C" char StrCase_Cap (char ch); | |
64 | ||
65 | /* | |
66 | Lower - converts an upper case character into a lower case character. | |
67 | If the character is not an upper case character 'A'..'Z' | |
68 | then the character is simply returned unaltered. | |
69 | */ | |
70 | ||
71 | extern "C" char StrCase_Lower (char ch); | |
72 | ||
73 | ||
74 | /* | |
75 | StrToUpperCase - converts string, a, to uppercase returning the | |
76 | result in, b. | |
77 | */ | |
78 | ||
79 | extern "C" void StrCase_StrToUpperCase (const char *a_, unsigned int _a_high, char *b, unsigned int _b_high) | |
80 | { | |
81 | unsigned int higha; | |
82 | unsigned int highb; | |
83 | unsigned int i; | |
84 | char a[_a_high+1]; | |
85 | ||
86 | /* make a local copy of each unbounded array. */ | |
87 | memcpy (a, a_, _a_high+1); | |
88 | ||
89 | higha = StrLib_StrLen ((const char *) a, _a_high); | |
90 | highb = _b_high; | |
91 | i = 0; | |
92 | while (((i < higha) && (a[i] != ASCII_nul)) && (i < highb)) | |
93 | { | |
94 | b[i] = StrCase_Cap (a[i]); | |
95 | i += 1; | |
96 | } | |
97 | if (i < highb) | |
98 | { | |
99 | b[i] = ASCII_nul; | |
100 | } | |
101 | } | |
102 | ||
103 | ||
104 | /* | |
105 | StrToLowerCase - converts string, a, to lowercase returning the | |
106 | result in, b. | |
107 | */ | |
108 | ||
109 | extern "C" void StrCase_StrToLowerCase (const char *a_, unsigned int _a_high, char *b, unsigned int _b_high) | |
110 | { | |
111 | unsigned int higha; | |
112 | unsigned int highb; | |
113 | unsigned int i; | |
114 | char a[_a_high+1]; | |
115 | ||
116 | /* make a local copy of each unbounded array. */ | |
117 | memcpy (a, a_, _a_high+1); | |
118 | ||
119 | higha = StrLib_StrLen ((const char *) a, _a_high); | |
120 | highb = _b_high; | |
121 | i = 0; | |
122 | while (((i < higha) && (a[i] != ASCII_nul)) && (i < highb)) | |
123 | { | |
124 | b[i] = StrCase_Lower (a[i]); | |
125 | i += 1; | |
126 | } | |
127 | if (i < highb) | |
128 | { | |
129 | b[i] = ASCII_nul; | |
130 | } | |
131 | } | |
132 | ||
133 | ||
134 | /* | |
135 | Cap - converts a lower case character into a capital character. | |
136 | If the character is not a lower case character 'a'..'z' | |
137 | then the character is simply returned unaltered. | |
138 | */ | |
139 | ||
140 | extern "C" char StrCase_Cap (char ch) | |
141 | { | |
142 | if ((ch >= 'a') && (ch <= 'z')) | |
143 | { | |
144 | ch = ((char) (( ((unsigned int) (ch))- ((unsigned int) ('a')))+ ((unsigned int) ('A')))); | |
145 | } | |
146 | return ch; | |
147 | /* static analysis guarentees a RETURN statement will be used before here. */ | |
148 | __builtin_unreachable (); | |
149 | } | |
150 | ||
151 | ||
152 | /* | |
153 | Lower - converts an upper case character into a lower case character. | |
154 | If the character is not an upper case character 'A'..'Z' | |
155 | then the character is simply returned unaltered. | |
156 | */ | |
157 | ||
158 | extern "C" char StrCase_Lower (char ch) | |
159 | { | |
160 | if ((ch >= 'A') && (ch <= 'Z')) | |
161 | { | |
162 | ch = ((char) (( ((unsigned int) (ch))- ((unsigned int) ('A')))+ ((unsigned int) ('a')))); | |
163 | } | |
164 | return ch; | |
165 | /* static analysis guarentees a RETURN statement will be used before here. */ | |
166 | __builtin_unreachable (); | |
167 | } | |
168 | ||
169 | extern "C" void _M2_StrCase_init (__attribute__((unused)) int argc,__attribute__((unused)) char *argv[],__attribute__((unused)) char *envp[]) | |
170 | { | |
171 | } | |
172 | ||
173 | extern "C" void _M2_StrCase_finish (__attribute__((unused)) int argc,__attribute__((unused)) char *argv[],__attribute__((unused)) char *envp[]) | |
174 | { | |
175 | } |