mirror of
https://github.com/jtgans/g13gui.git
synced 2025-06-20 08:23:50 -04:00
g13d: Migrate string_repr_out into a cc file and fix the deps
This was a mistake I made accidentally -- meant to have the function in the C++ file, not in the header.
This commit is contained in:
parent
073860faad
commit
73f10be688
@ -19,6 +19,7 @@ add_executable(g13d
|
|||||||
main.cc
|
main.cc
|
||||||
stick.cc
|
stick.cc
|
||||||
manager.cc
|
manager.cc
|
||||||
|
repr.cc
|
||||||
)
|
)
|
||||||
|
|
||||||
target_compile_definitions(g13d PRIVATE BOOST_LOG_DYN_LINK=1)
|
target_compile_definitions(g13d PRIVATE BOOST_LOG_DYN_LINK=1)
|
||||||
|
55
g13d/repr.cc
Normal file
55
g13d/repr.cc
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
#include <ostream>
|
||||||
|
|
||||||
|
#include "repr.h"
|
||||||
|
|
||||||
|
namespace G13 {
|
||||||
|
|
||||||
|
void string_repr_out::write_on(std::ostream &o) const {
|
||||||
|
const char *cp = s.c_str();
|
||||||
|
const char *end = cp + s.size();
|
||||||
|
|
||||||
|
o << "\"";
|
||||||
|
|
||||||
|
while (cp < end) {
|
||||||
|
switch (*cp) {
|
||||||
|
case '\n':
|
||||||
|
o << "\\n";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '\r':
|
||||||
|
o << "\\r";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '\0':
|
||||||
|
o << "\\0";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '\t':
|
||||||
|
o << "\\t";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '\\':
|
||||||
|
case '\'':
|
||||||
|
case '\"':
|
||||||
|
o << "\\" << *cp;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default: {
|
||||||
|
char c = *cp;
|
||||||
|
if (c < 32) {
|
||||||
|
char hi = '0' + (c & 0x0f);
|
||||||
|
char lo = '0' + ((c >> 4) & 0x0f);
|
||||||
|
o << "\\x" << hi << lo;
|
||||||
|
} else {
|
||||||
|
o << c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cp++;
|
||||||
|
}
|
||||||
|
|
||||||
|
o << "\"";
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace G13
|
48
g13d/repr.h
48
g13d/repr.h
@ -6,54 +6,6 @@
|
|||||||
|
|
||||||
namespace G13 {
|
namespace G13 {
|
||||||
|
|
||||||
void string_repr_out::write_on(std::ostream &o) const {
|
|
||||||
const char *cp = s.c_str();
|
|
||||||
const char *end = cp + s.size();
|
|
||||||
|
|
||||||
o << "\"";
|
|
||||||
|
|
||||||
while (cp < end) {
|
|
||||||
switch (*cp) {
|
|
||||||
case '\n':
|
|
||||||
o << "\\n";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case '\r':
|
|
||||||
o << "\\r";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case '\0':
|
|
||||||
o << "\\0";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case '\t':
|
|
||||||
o << "\\t";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case '\\':
|
|
||||||
case '\'':
|
|
||||||
case '\"':
|
|
||||||
o << "\\" << *cp;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default: {
|
|
||||||
char c = *cp;
|
|
||||||
if (c < 32) {
|
|
||||||
char hi = '0' + (c & 0x0f);
|
|
||||||
char lo = '0' + ((c >> 4) & 0x0f);
|
|
||||||
o << "\\x" << hi << lo;
|
|
||||||
} else {
|
|
||||||
o << c;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cp++;
|
|
||||||
}
|
|
||||||
|
|
||||||
o << "\"";
|
|
||||||
};
|
|
||||||
|
|
||||||
struct string_repr_out {
|
struct string_repr_out {
|
||||||
string_repr_out(const std::string &str) : s(str) {}
|
string_repr_out(const std::string &str) : s(str) {}
|
||||||
void write_on(std::ostream &) const;
|
void write_on(std::ostream &) const;
|
||||||
|
Loading…
Reference in New Issue
Block a user