-/* $Id$
-
-This file is part of libmspstrings
-Copyright © 2006-2008 Mikko Rasa
-Distributed under the LGPL
-*/
-
#include <algorithm>
#include <list>
-#include <msp/core/except.h>
+#include <stdexcept>
#include "utils.h"
using namespace std;
else if(*i>='A' && *i<='F')
digit = *i-'A'+10;
else
- throw InvalidParameterValue("Invalid hexadecimal digit");
+ throw invalid_argument("c_unescape");
numeric_value = (numeric_value<<4 | digit);
++numeric_pos;
if(*i>='0' && *i<='7')
digit = *i-'0';
else
- throw InvalidParameterValue("Invalid octal digit");
+ throw invalid_argument("c_unescape");
numeric_value = (numeric_value<<3 | digit);
++numeric_pos;
else if(*i=='\\')
result += '\\';
else
- throw InvalidParameterValue("Invalid escape sequence");
+ throw invalid_argument("c_unescape");
escape = false;
}
}
if(escape)
- throw InvalidParameterValue("Stray backslash at end of string");
+ throw invalid_argument("c_unescape");
return result;
}
result += "\\\\";
else if(static_cast<unsigned char>(*i)<' ' || (escape_8bit && (*i&0x80)))
{
- char buf[4] = {'\\', '0'+((*i>>6)&3), '0'+((*i>>3)&7), '0'+(*i&7)};
+ char buf[4] = { '\\', 0 };
+ for(unsigned j=0; j<3; ++j)
+ buf[1+j] = '0'+((static_cast<unsigned char>(*i)>>(6-j*3))&7);
result.append(buf, 4);
}
else