-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKhuString.cpp
More file actions
147 lines (120 loc) · 3.37 KB
/
KhuString.cpp
File metadata and controls
147 lines (120 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#pragma once
#include <iostream>
#include "KhuString.h"
using namespace std;
namespace khu
{
char* gString = nullptr;
const char* khu::Construct(const char* str)
{
int length = 0;
while (true)
{
if (str[length] == '\0')
{
break;
}
else
{
length++;
}
}
gString = new char[length + 1];
for (int i = 0; i < length + 1; i++)
{
*(gString + i) = str[i];
}
return gString;
}
unsigned int khu::GetLength()
{
int index = 0;
while (1)
{
if (gString[index] == '\0')
{
return index + 1;
}
index++;
}
cout << index;
}
void khu::Append(const char* str)
{
int gStringLength = GetLength(); //GetLength함수 변수로 선언
int strLength = 0;
while (true)
{
if (str[strLength] == '\0')
{
strLength++;
break; //str[strLength]값이 null이면 strLength값을 +1해주고 while문 빠져나옴.
}
strLength++; //str[strLenght]값이 null이기 전에는 strLength +1
}
char* tmpGString = gString;
int newLength = gStringLength + strLength;
gString = new char[newLength]; //gString 배열의 크기를 할당해줌(정해져있는 크기가 아니므로 동적할당필요)
for (int i = 0; i < gStringLength - 1; i++)
{
*(gString + i) = tmpGString[i]; //배열이름은 시작주소(0번째 인덱스)이므로 *(gString+i)와 tmpGString[i]는 같은 값
} //tmpString에 gStringLength만큼 for문 돌려서 원소 넣어줌
for (int i = 0; i < strLength; i++)
{
int offset = (gStringLength - 1) + i;//(gStringLength원소(-1은 null값)) + strLength만큼 for문 돌려 더한 합
*(gString + offset) = str[i]; //배열이름은 시작주소(0번째 인덱스)이므로 *(gString+offset)와 str[i]는 같은 값
}
}
void khu::Reverse()
{
int gStringLength = GetLength();
for (int i = 0; i < gStringLength - 1; ++i)
{
gString[gStringLength - i - 1];
}
gString[gStringLength] = NULL;
}
void khu::ToUpper()
{
int gStringLength = GetLength();
for (int i = 0; i < gStringLength - 1; i++)
{
if (gString[i] >= 'a' && gString[i] <= 'z')
{
gString[i] = gString[i] - 32;
}
}
}
void khu::ToLower()
{
int gStringLength = GetLength();
for (int i = 0; i < gStringLength - 1; i++)
{
if (gString[i] >= 'A' && gString[i] <= 'Z')
{
gString[i] = gString[i] + 32;
}
}
}
const char* khu::Copy(const char* str)
{
int length = 0;
while (true)
{
if (str[length] == '\0')
{
break;
}
else
{
length++;
}
}
gString = new char[length + 1];
for (int i = 0; i < length + 1; i++)
{
*(gString + i) = str[i];
}
return gString;
}
}