]>
git.saurik.com Git - apple/mdnsresponder.git/blob - mDNSMacOSX/BonjourTop/source/bjstring.cpp
5 // Created by Terrin Eager on 9/26/12.
19 BJString::BJString(const BJString
& scr
)
25 BJString::BJString(const char* str
)
39 BJString
& BJString::operator=(const char* str
)
45 BJString
& BJString::operator=(const BJString
& str
)
51 bool BJString::operator==(const char* str
)
53 if (buffer
== NULL
&& str
== NULL
)
55 if (buffer
== NULL
|| str
== NULL
)
58 return (strcmp(str
,buffer
) == 0);
60 bool BJString::operator==(const BJString
& str
)
62 if (buffer
== NULL
&& str
.GetBuffer() == NULL
)
64 if (buffer
== NULL
|| str
.GetBuffer() == NULL
)
66 return (strcmp(str
.GetBuffer(),buffer
) == 0);
69 bool BJString::operator<(const BJString
& str
) const
71 const char* myBuff
= GetBuffer();
72 const char* otherBuff
= str
.GetBuffer();
74 if (myBuff
== NULL
&& otherBuff
== NULL
)
76 if (myBuff
!= NULL
&& otherBuff
== NULL
)
78 if (myBuff
== NULL
&& otherBuff
!= NULL
)
81 int cmp
= strcmp(myBuff
, otherBuff
);
90 BJ_COMPARE
BJString::Compare(const BJString
& str
)
92 const char* myBuff
= GetBuffer();
93 const char* otherBuff
= str
.GetBuffer();
95 if (myBuff
== NULL
&& otherBuff
== NULL
)
97 if (myBuff
!= NULL
&& otherBuff
== NULL
)
99 if (myBuff
== NULL
&& otherBuff
!= NULL
)
102 int cmp
= strcmp(myBuff
, otherBuff
);
113 BJString
& BJString::operator+=(const char* str
)
116 return operator=(str
);
120 BJString temp
= buffer
;
121 Create((BJ_UINT32
)(strlen(buffer
) + strlen(str
)));
122 strlcpy(buffer
, temp
.GetBuffer(), length
+ 1);
123 strlcat(buffer
, str
, length
+ 1);
126 BJString
& BJString::operator+=(const BJString
&str
)
128 operator+=(str
.GetBuffer());
133 const char* BJString::GetBuffer() const
138 void BJString::Set(const char* str
)
141 BJ_UINT32 len
= str
?(BJ_UINT32
)strlen(str
):0;
146 strlcpy(buffer
, str
, length
+ 1);
149 void BJString::Set(const char* str
, BJ_UINT32 len
)
155 strncpy(buffer
, str
, len
);
157 memset(buffer
, 0, length
);
161 void BJString::Append(const char* str
, BJ_UINT32 len
)
163 if (length
< (strlen(buffer
) + strlen(str
)))
165 BJString temp
= buffer
;
166 Create((BJ_UINT32
)(strlen(buffer
) + strlen(str
)));
167 if (buffer
&& temp
.buffer
)
168 strlcpy(buffer
, temp
.GetBuffer(), length
+ 1);
170 strncat(buffer
,str
,len
);
173 bool BJString::Contains(const char* str
)
175 if (buffer
== NULL
&& str
== NULL
)
177 if (buffer
== NULL
|| str
== NULL
)
179 return (strstr(buffer
,str
) != NULL
);
182 BJ_UINT32
BJString::GetUINT32()
190 void BJString::Format(BJ_UINT64 number
,BJ_FORMAT_STYLE style
)
195 sprintf(buffer
,"%llu",number
);
199 char formatedTime
[24];
200 time_t timeValue
= number
;
201 struct tm
* timeStruct
= localtime(&timeValue
);
202 strftime(formatedTime
, sizeof(formatedTime
), "%Y-%m-%d_%T_%a", timeStruct
);
212 void BJString::Create(BJ_UINT32 len
)
218 memset(buffer
, 0, len
+ 1);
226 buffer
= new char[len
+1];
229 memset(buffer
, 0, len
+1);
234 BJ_UINT32
BJString::GetLength()
236 return buffer
?(BJ_UINT32
)strlen(buffer
):0;