2011-09-29 12:44:49 +00:00
|
|
|
#ifdef NALL_STRING_INTERNAL_HPP
|
2010-08-09 13:28:56 +00:00
|
|
|
|
2011-10-02 10:05:45 +00:00
|
|
|
//BSV v1.0 parser
|
|
|
|
//revision 0.02
|
2010-08-09 13:28:56 +00:00
|
|
|
|
|
|
|
namespace nall {
|
|
|
|
|
2011-09-29 12:44:49 +00:00
|
|
|
struct BSV {
|
|
|
|
static inline string decode(const char *input) {
|
|
|
|
string output;
|
|
|
|
unsigned offset = 0;
|
|
|
|
while(*input) {
|
|
|
|
//illegal characters
|
|
|
|
if(*input == '}' ) return "";
|
|
|
|
if(*input == '\r') return "";
|
|
|
|
if(*input == '\n') return "";
|
2010-08-09 13:28:56 +00:00
|
|
|
|
2011-09-29 12:44:49 +00:00
|
|
|
//normal characters
|
|
|
|
if(*input != '{') { output[offset++] = *input++; continue; }
|
2010-08-09 13:28:56 +00:00
|
|
|
|
2011-09-29 12:44:49 +00:00
|
|
|
//entities
|
|
|
|
if(strbegin(input, "{lf}")) { output[offset++] = '\n'; input += 4; continue; }
|
|
|
|
if(strbegin(input, "{lb}")) { output[offset++] = '{'; input += 4; continue; }
|
|
|
|
if(strbegin(input, "{rb}")) { output[offset++] = '}'; input += 4; continue; }
|
2010-08-09 13:28:56 +00:00
|
|
|
|
2011-09-29 12:44:49 +00:00
|
|
|
//illegal entities
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
output[offset] = 0;
|
|
|
|
return output;
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 12:44:49 +00:00
|
|
|
static inline string encode(const char *input) {
|
|
|
|
string output;
|
|
|
|
unsigned offset = 0;
|
|
|
|
while(*input) {
|
|
|
|
//illegal characters
|
|
|
|
if(*input == '\r') return "";
|
2010-08-09 13:28:56 +00:00
|
|
|
|
2011-09-29 12:44:49 +00:00
|
|
|
if(*input == '\n') {
|
|
|
|
output[offset++] = '{';
|
|
|
|
output[offset++] = 'l';
|
|
|
|
output[offset++] = 'f';
|
|
|
|
output[offset++] = '}';
|
|
|
|
input++;
|
|
|
|
continue;
|
|
|
|
}
|
2010-08-09 13:28:56 +00:00
|
|
|
|
2011-09-29 12:44:49 +00:00
|
|
|
if(*input == '{') {
|
|
|
|
output[offset++] = '{';
|
|
|
|
output[offset++] = 'l';
|
|
|
|
output[offset++] = 'b';
|
|
|
|
output[offset++] = '}';
|
|
|
|
input++;
|
|
|
|
continue;
|
|
|
|
}
|
2010-08-09 13:28:56 +00:00
|
|
|
|
2011-09-29 12:44:49 +00:00
|
|
|
if(*input == '}') {
|
|
|
|
output[offset++] = '{';
|
|
|
|
output[offset++] = 'r';
|
|
|
|
output[offset++] = 'b';
|
|
|
|
output[offset++] = '}';
|
|
|
|
input++;
|
|
|
|
continue;
|
|
|
|
}
|
2010-08-09 13:28:56 +00:00
|
|
|
|
2011-09-29 12:44:49 +00:00
|
|
|
output[offset++] = *input++;
|
|
|
|
}
|
|
|
|
output[offset] = 0;
|
|
|
|
return output;
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
2011-09-29 12:44:49 +00:00
|
|
|
};
|
2010-08-09 13:28:56 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|