Debian Codegraph @

plugins/aiksaurus/aiksaurusgtk3/AiksaurusGTK_utils.cpp

raw
1 /*
2 * AiksaurusGTK - A GTK interface to the AikSaurus library
3 * Copyright (C) 2001 by Jared Davis
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
18 * 02111-1307, USA.
19 */
20
21 // header file that we are implementing here.
22 #include "AiksaurusGTK_utils.h"
23
24 // cstring needed for strlen.
25 #include <cstring>
26
27 // new needed for nothrow.
28 #include <new>
29
30
31 bool AiksaurusGTK_strEquals(const char* lhs, const char* rhs)
32 {
33 if ((!lhs) || (!rhs))
34 return (lhs == rhs);
35
36 register int i = 0;
37 while(lhs[i] != '\0')
38 {
39 if (rhs[i] != lhs[i])
40 return false;
41
42 ++i;
43 }
44
45 return (rhs[i] == '\0');
46 }
47
48
49 char* AiksaurusGTK_strCopy(const char* str)
50 {
51 char* ret;
52
53 if (!str)
54 {
55 ret = new(std::nothrow) char[1];
56
57 if (!ret)
58 return ret;
59
60 ret[0] = '\0';
61
62 }
63
64 else
65 {
66 const int len = strlen(str);
67
68 ret = new(std::nothrow) char[len+1];
69
70 if (!ret)
71 return ret;
72
73 for(register int i = 0;i < len;++i)
74 {
75 ret[i] = str[i];
76 }
77
78 ret[len] = '\0';
79 }
80
81 return ret;
82 }
83
84
85 char* AiksaurusGTK_strConcat(const char* a, const char* b)
86 {
87 int len_a = strlen(a);
88 int len_b = strlen(b);
89
90 char* ret = new(std::nothrow) char[len_a + len_b + 1];
91
92 if (!ret)
93 return ret;
94
95 register int i = 0;
96
97 while(i < len_a)
98 {
99 ret[i] = a[i];
100 ++i;
101 }
102
103 while(i < len_b + len_a)
104 {
105 ret[i] = b[i - len_a];
106 ++i;
107 }
108
109 ret[len_a + len_b] = '\0';
110
111 return ret;
112 }