acme
Foundational cross-platform layer of the ca2 framework
Toggle main menu visibility
Loading...
Searching...
No Matches
c_string.h
1
// Created by camilo on 2023-11-25 21:17 <3ThomasBorregaardSorensen!!
2
#pragma once
3
4
5
#include "acme/platform/c.h"
6
#include <string.h>
7
8
namespace
c
9
{
10
11
class
CLASS_DECL_ACME string
12
{
13
public
:
14
15
char_pointer m_psz;
16
string()
17
{
18
m_psz =
nullptr
;
19
}
20
string(const_char_pointer psz)
21
{
22
if
(psz)
23
{
24
m_psz = strdup(psz);
25
}
26
else
27
{
28
m_psz =
nullptr
;
29
}
30
}
31
string(const ::c::string & str)
32
{
33
if
(str.m_psz)
34
{
35
m_psz = strdup(str.m_psz);
36
}
37
else
38
{
39
m_psz =
nullptr
;
40
}
41
}
42
string(
::c::string
&& str)
43
{
44
auto
psz = str.m_psz;
45
str.m_psz =
nullptr
;
46
m_psz = psz;
47
}
48
~string()
49
{
50
destroy();
51
}
52
void
destroy()
53
{
54
auto
psz = m_psz;
55
m_psz =
nullptr
;
56
if
(psz) free(psz);
57
}
58
string
& operator = (nullptr_t)
59
{
60
destroy();
61
return
*
this
;
62
}
63
string
& operator = (const ::c::string & str) {
64
if
(m_psz != str.m_psz) {
65
destroy();
66
if
(str.m_psz)
67
{
68
m_psz = strdup(str.m_psz);
69
}
70
}
71
return
*
this
;
72
}
73
string
& operator = (const_char_pointer psz) {
74
if
(psz != m_psz)
75
{
76
destroy();
77
if
(psz)
78
{
79
m_psz = strdup(psz);
80
}
81
}
82
return
*
this
;
83
}
84
string
& operator = (
string
&& str)
noexcept
{
85
if
(m_psz != str.m_psz) {
86
destroy();
87
auto
psz = str.m_psz;
88
str.m_psz =
nullptr
;
89
m_psz = psz;
90
}
91
return
*
this
;
92
93
}
94
95
operator
const_char_pointer ()
const
{
return
m_psz; }
96
97
bool
operator == (const_char_pointer psz)
98
{
99
100
return
!strcmp(m_psz, psz);
101
}
102
103
::i32 size()
const
;
104
105
::i32 find_replace(const_char_pointer search, const_char_pointer replace);
106
::i32 find_replace(::i8 search, ::i8 replace);
107
108
string
& operator += (const_char_pointer p);
109
110
};
111
112
}
// namespace c
113
114
115
116
c::string
Definition
c_string.h:12
prototype
string
c_string.h
Generated by
1.17.0