From f94cc9d9c6aa1b1bddb1f32f30e4647a761ff826 Mon Sep 17 00:00:00 2001 From: Evgeniy Gatov Date: Thu, 18 Apr 2013 11:49:46 +0000 Subject: [PATCH] DMBS: tiny fix [#CONV-4143]. --- dbms/include/DB/Common/escapeForFileName.h | 36 +++++++++------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/dbms/include/DB/Common/escapeForFileName.h b/dbms/include/DB/Common/escapeForFileName.h index ce97307cdfb..f4cd8f96436 100644 --- a/dbms/include/DB/Common/escapeForFileName.h +++ b/dbms/include/DB/Common/escapeForFileName.h @@ -30,6 +30,19 @@ inline std::string escapeForFileName(const std::string & s) return res; } +inline char unhex(char c) +{ + switch (c) + { + case '0' ... '9': + return c - '0'; + case 'A' ... 'F': + return c - 'A' + 10; + default: + return 0; + } +} + inline std::string unescapeForFileName(const std::string & s) { std::string res; @@ -48,31 +61,12 @@ inline std::string unescapeForFileName(const std::string & s) if (++pos == end) break; c = *pos; - char val = 0; - - switch (c) - { - case '0' ... '9': - val = (c - '0') * 16; - break; - case 'A' ... 'F': - val = (c - 'A' + 10) * 16; - break; - }; + char val = unhex(val) * 16; if (++pos == end) break; c = *pos; - switch (c) - { - case '0' ... '9': - val += (c - '0'); - break; - case 'A' ... 'F': - val += c - 'A' + 10; - break; - }; - res += val; + res += unhex(val); } ++pos;