34 if (strlen(pSepLevelsPtr) < 2) {
46 char vSepFirstLevel = pSepLevelsPtr[0];
47 char vSepSecondLevel = pSepLevelsPtr[1];
49 bool vCheckingName =
true;
50 bool vCheckingValue =
false;
52 size_t vSourceLen = strlen(pSourcePtr);
54 for (
size_t vIdx=0; vIdx<vSourceLen; vIdx++) {
56 char vAt = pSourcePtr[vIdx];
59 if (vAt == vSepSecondLevel) {
60 vCheckingName =
false;
61 vCheckingValue =
true;
69 vThisName[vTokenIdx] = vAt;
73 else if (vCheckingValue) {
74 if (vAt == vSepFirstLevel) {
76 vCheckingValue =
false;
79 string vThisNameStr(vThisName);
80 string vThisValueStr(vThisValue);
82 pDestRef.
put(vThisNameStr,vThisValueStr);
92 vThisValue[vTokenIdx] = vAt;
124 size_t vSourceLength = pSourceRef.length();
126 if (0 == vSourceLength) {
131 size_t vSepSize = pSeparator.length();
132 size_t vCurrentPos = 0;
133 size_t vPreviousPos = 0;
134 size_t vMaxPos = vSourceLength - vSepSize;
143 while (vCurrentPos != string::npos) {
145 vCurrentPos = pSourceRef.find(pSeparator,vPreviousPos);
147 if (string::npos == vCurrentPos) {
148 vSample = pSourceRef.substr(vPreviousPos);
151 vSample = pSourceRef.substr(vPreviousPos,vCurrentPos - vPreviousPos);
153 if (vCurrentPos > vMaxPos) {
154 vCurrentPos = string::npos;
157 vPreviousPos = vCurrentPos + vSepSize;
160 pDestRef.
push(vSample);
172 ErrorCode StringTool::toHex(
void* pSource,
size_t pSize,
string& pDestination) {
174 for (
size_t vIdx=0; vIdx < pSize; vIdx++) {
175 unsigned char vValue = ((
char*)pSource)[vIdx];
176 unsigned char vValueHex[3];
177 unsigned char vHigh =
HEXVALUES[vValue>>4];
178 unsigned char vLow =
HEXVALUES[vValue&0x0F];
179 vValueHex[0] = vHigh;
182 pDestination.append((
char*)vValueHex);
189 ErrorCode StringTool::fromHex(
string& pSource,
void* pDestination,
size_t pDestinationSize) {
193 size_t vSize = pSource.size();
199 }
else if ((vSize / 2) > pDestinationSize) {
205 char* vStr = (
char*) (pSource.c_str());
206 char* vPtr = (
char*) (pDestination);
210 for (
size_t vPointer = 0; vPointer < vSize; vPointer += 2) {
218 char vHigh =
static_cast<char>(
REVHEX[(int)vStr[vPointer]] << 4);
219 char vLow =
static_cast<char>(
REVHEX[(int)vStr[vPointer + 1]]);
220 char vValue =
static_cast<char>(vHigh + vLow);
221 vPtr[vDataIdx] = vValue;
240 size_t vTotal = pStringRef.size();
246 const char* vPtr = pStringRef.c_str();
248 bool vEndLoop =
false;
260 if (vIndex == vTotal) {
266 if (isspace(vPtr[vIndex])) {
270 pStringRef.erase(0,vIndex);
282 ErrorCode StringTool::drop(
string& pStringRef,
const char* pDropHead) {
288 if (pStringRef.size()>0) {
289 size_t vPos = pStringRef.find(pDropHead);
291 if (pStringRef.npos != vPos) {
292 pStringRef.erase(vPos,pStringRef.npos);