summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/common/profiler.cpp3
-rw-r--r--src/common/string_util.cpp125
-rw-r--r--src/common/string_util.h2
3 files changed, 1 insertions, 129 deletions
diff --git a/src/common/profiler.cpp b/src/common/profiler.cpp
index b8cde1785..cf6b6b258 100644
--- a/src/common/profiler.cpp
+++ b/src/common/profiler.cpp
@@ -126,10 +126,9 @@ void TimingResultsAggregator::AddFrame(const ProfilingFrameResult& frame_result)
126static AggregatedDuration AggregateField(const std::vector<Duration>& v, size_t len) { 126static AggregatedDuration AggregateField(const std::vector<Duration>& v, size_t len) {
127 AggregatedDuration result; 127 AggregatedDuration result;
128 result.avg = Duration::zero(); 128 result.avg = Duration::zero();
129
130 result.min = result.max = (len == 0 ? Duration::zero() : v[0]); 129 result.min = result.max = (len == 0 ? Duration::zero() : v[0]);
131 130
132 for (size_t i = 1; i < len; ++i) { 131 for (size_t i = 0; i < len; ++i) {
133 Duration value = v[i]; 132 Duration value = v[i];
134 result.avg += value; 133 result.avg += value;
135 result.min = std::min(result.min, value); 134 result.min = std::min(result.min, value);
diff --git a/src/common/string_util.cpp b/src/common/string_util.cpp
index 6563611fd..3a6e51daa 100644
--- a/src/common/string_util.cpp
+++ b/src/common/string_util.cpp
@@ -287,131 +287,6 @@ std::string ReplaceAll(std::string result, const std::string& src, const std::st
287 return result; 287 return result;
288} 288}
289 289
290// UriDecode and UriEncode are from http://www.codeguru.com/cpp/cpp/string/conversions/print.php/c12759
291// by jinq0123 (November 2, 2006)
292
293// Uri encode and decode.
294// RFC1630, RFC1738, RFC2396
295
296//#include <string>
297//#include <assert.h>
298
299const char HEX2DEC[256] =
300{
301 /* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
302 /* 0 */ 16,16,16,16, 16,16,16,16, 16,16,16,16, 16,16,16,16,
303 /* 1 */ 16,16,16,16, 16,16,16,16, 16,16,16,16, 16,16,16,16,
304 /* 2 */ 16,16,16,16, 16,16,16,16, 16,16,16,16, 16,16,16,16,
305 /* 3 */ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,16,16, 16,16,16,16,
306
307 /* 4 */ 16,10,11,12, 13,14,15,16, 16,16,16,16, 16,16,16,16,
308 /* 5 */ 16,16,16,16, 16,16,16,16, 16,16,16,16, 16,16,16,16,
309 /* 6 */ 16,10,11,12, 13,14,15,16, 16,16,16,16, 16,16,16,16,
310 /* 7 */ 16,16,16,16, 16,16,16,16, 16,16,16,16, 16,16,16,16,
311
312 /* 8 */ 16,16,16,16, 16,16,16,16, 16,16,16,16, 16,16,16,16,
313 /* 9 */ 16,16,16,16, 16,16,16,16, 16,16,16,16, 16,16,16,16,
314 /* A */ 16,16,16,16, 16,16,16,16, 16,16,16,16, 16,16,16,16,
315 /* B */ 16,16,16,16, 16,16,16,16, 16,16,16,16, 16,16,16,16,
316
317 /* C */ 16,16,16,16, 16,16,16,16, 16,16,16,16, 16,16,16,16,
318 /* D */ 16,16,16,16, 16,16,16,16, 16,16,16,16, 16,16,16,16,
319 /* E */ 16,16,16,16, 16,16,16,16, 16,16,16,16, 16,16,16,16,
320 /* F */ 16,16,16,16, 16,16,16,16, 16,16,16,16, 16,16,16,16
321};
322
323std::string UriDecode(const std::string & sSrc)
324{
325 // Note from RFC1630: "Sequences which start with a percent sign
326 // but are not followed by two hexadecimal characters (0-9, A-F) are reserved
327 // for future extension"
328
329 const unsigned char * pSrc = (const unsigned char *)sSrc.c_str();
330 const size_t SRC_LEN = sSrc.length();
331 const unsigned char * const SRC_END = pSrc + SRC_LEN;
332 const unsigned char * const SRC_LAST_DEC = SRC_END - 2; // last decodable '%'
333
334 char * const pStart = new char[SRC_LEN];
335 char * pEnd = pStart;
336
337 while (pSrc < SRC_LAST_DEC)
338 {
339 if (*pSrc == '%')
340 {
341 char dec1, dec2;
342 if (16 != (dec1 = HEX2DEC[*(pSrc + 1)])
343 && 16 != (dec2 = HEX2DEC[*(pSrc + 2)]))
344 {
345 *pEnd++ = (dec1 << 4) + dec2;
346 pSrc += 3;
347 continue;
348 }
349 }
350
351 *pEnd++ = *pSrc++;
352 }
353
354 // the last 2- chars
355 while (pSrc < SRC_END)
356 *pEnd++ = *pSrc++;
357
358 std::string sResult(pStart, pEnd);
359 delete [] pStart;
360 return sResult;
361}
362
363// Only alphanum is safe.
364const char SAFE[256] =
365{
366 /* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
367 /* 0 */ 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
368 /* 1 */ 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
369 /* 2 */ 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
370 /* 3 */ 1,1,1,1, 1,1,1,1, 1,1,0,0, 0,0,0,0,
371
372 /* 4 */ 0,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1,
373 /* 5 */ 1,1,1,1, 1,1,1,1, 1,1,1,0, 0,0,0,0,
374 /* 6 */ 0,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1,
375 /* 7 */ 1,1,1,1, 1,1,1,1, 1,1,1,0, 0,0,0,0,
376
377 /* 8 */ 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
378 /* 9 */ 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
379 /* A */ 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
380 /* B */ 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
381
382 /* C */ 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
383 /* D */ 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
384 /* E */ 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
385 /* F */ 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0
386};
387
388std::string UriEncode(const std::string & sSrc)
389{
390 const char DEC2HEX[16 + 1] = "0123456789ABCDEF";
391 const unsigned char * pSrc = (const unsigned char *)sSrc.c_str();
392 const size_t SRC_LEN = sSrc.length();
393 unsigned char * const pStart = new unsigned char[SRC_LEN * 3];
394 unsigned char * pEnd = pStart;
395 const unsigned char * const SRC_END = pSrc + SRC_LEN;
396
397 for (; pSrc < SRC_END; ++pSrc)
398 {
399 if (SAFE[*pSrc])
400 *pEnd++ = *pSrc;
401 else
402 {
403 // escape this char
404 *pEnd++ = '%';
405 *pEnd++ = DEC2HEX[*pSrc >> 4];
406 *pEnd++ = DEC2HEX[*pSrc & 0x0F];
407 }
408 }
409
410 std::string sResult((char *)pStart, (char *)pEnd);
411 delete [] pStart;
412 return sResult;
413}
414
415#ifdef _MSC_VER 290#ifdef _MSC_VER
416 291
417std::string UTF16ToUTF8(const std::u16string& input) 292std::string UTF16ToUTF8(const std::u16string& input)
diff --git a/src/common/string_util.h b/src/common/string_util.h
index a60a84696..356da5b60 100644
--- a/src/common/string_util.h
+++ b/src/common/string_util.h
@@ -86,8 +86,6 @@ bool SplitPath(const std::string& full_path, std::string* _pPath, std::string* _
86 86
87void BuildCompleteFilename(std::string& _CompleteFilename, const std::string& _Path, const std::string& _Filename); 87void BuildCompleteFilename(std::string& _CompleteFilename, const std::string& _Path, const std::string& _Filename);
88std::string ReplaceAll(std::string result, const std::string& src, const std::string& dest); 88std::string ReplaceAll(std::string result, const std::string& src, const std::string& dest);
89std::string UriDecode(const std::string & sSrc);
90std::string UriEncode(const std::string & sSrc);
91 89
92std::string UTF16ToUTF8(const std::u16string& input); 90std::string UTF16ToUTF8(const std::u16string& input);
93std::u16string UTF8ToUTF16(const std::string& input); 91std::u16string UTF8ToUTF16(const std::string& input);