Debian Codegraph @

gcc/m2/gm2-libs/StrCase.mod

raw
1 (* StrCase.mod provides procedure to convert between text case.
2
3 Copyright (C) 2001-2025 Free Software Foundation, Inc.
4 Contributed by Gaius Mulley <[email protected]>.
5
6 This file is part of GNU Modula-2.
7
8 GNU Modula-2 is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
11 any later version.
12
13 GNU Modula-2 is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
17
18 Under Section 7 of GPL version 3, you are granted additional
19 permissions described in the GCC Runtime Library Exception, version
20 3.1, as published by the Free Software Foundation.
21
22 You should have received a copy of the GNU General Public License and
23 a copy of the GCC Runtime Library Exception along with this program;
24 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
25 <http://www.gnu.org/licenses/>. *)
26
27 IMPLEMENTATION MODULE StrCase ;
28
29
30 FROM ASCII IMPORT nul ;
31 FROM StrLib IMPORT StrLen ;
32
33
34 (*
35 StrToUpperCase - converts string, a, to uppercase returning the
36 result in, b.
37 *)
38
39 PROCEDURE StrToUpperCase (a: ARRAY OF CHAR ; VAR b: ARRAY OF CHAR) ;
40 VAR
41 higha,
42 highb,
43 i : CARDINAL ;
44 BEGIN
45 higha := StrLen(a) ;
46 highb := HIGH(b) ;
47 i := 0 ;
48 WHILE (i<higha) AND (a[i]#nul) AND (i<highb) DO
49 b[i] := Cap(a[i]) ;
50 INC(i)
51 END ;
52 IF i<highb
53 THEN
54 b[i] := nul
55 END
56 END StrToUpperCase ;
57
58
59 (*
60 StrToLowerCase - converts string, a, to lowercase returning the
61 result in, b.
62 *)
63
64 PROCEDURE StrToLowerCase (a: ARRAY OF CHAR ; VAR b: ARRAY OF CHAR) ;
65 VAR
66 higha,
67 highb,
68 i : CARDINAL ;
69 BEGIN
70 higha := StrLen(a) ;
71 highb := HIGH(b) ;
72 i := 0 ;
73 WHILE (i<higha) AND (a[i]#nul) AND (i<highb) DO
74 b[i] := Lower(a[i]) ;
75 INC(i)
76 END ;
77 IF i<highb
78 THEN
79 b[i] := nul
80 END
81 END StrToLowerCase ;
82
83
84 (*
85 Cap - converts a lower case character into a capital character.
86 If the character is not a lower case character 'a'..'z'
87 then the character is simply returned unaltered.
88 *)
89
90 PROCEDURE Cap (ch: CHAR) : CHAR ;
91 BEGIN
92 IF (ch>='a') AND (ch<='z')
93 THEN
94 ch := CHR( ORD(ch)-ORD('a')+ORD('A') )
95 END ;
96 RETURN( ch )
97 END Cap ;
98
99
100 (*
101 Lower - converts an upper case character into a lower case character.
102 If the character is not an upper case character 'A'..'Z'
103 then the character is simply returned unaltered.
104 *)
105
106 PROCEDURE Lower (ch: CHAR) : CHAR ;
107 BEGIN
108 IF (ch>='A') AND (ch<='Z')
109 THEN
110 ch := CHR( ORD(ch)-ORD('A')+ORD('a') )
111 END ;
112 RETURN( ch )
113 END Lower ;
114
115
116 END StrCase.