From 57972eb04214f28db371ec6edfef01a86e6acd9b Mon Sep 17 00:00:00 2001 From: Lukasz Gromanowski Date: Sun, 19 Jun 2011 19:33:30 +0200 Subject: [PATCH] Mantis: #18 - Move components from global namespace into their own namespace. Added namespace around generated win_1252 table. Added generation of header guard and ToUTF8 namespace in gen_iconv. Small corrections in Makefile. Signed-off-by: Lukasz Gromanowski --- components/to_utf8/Makefile | 5 ++++- components/to_utf8/gen_iconv.cpp | 15 +++++++++++++++ components/to_utf8/tables_gen.hpp | 11 +++++++++++ components/to_utf8/to_utf8.cpp | 2 +- 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/components/to_utf8/Makefile b/components/to_utf8/Makefile index a84cc240e..5234d455a 100644 --- a/components/to_utf8/Makefile +++ b/components/to_utf8/Makefile @@ -1,5 +1,8 @@ tables_gen.hpp: gen_iconv - gen_iconv > tables_gen.hpp + ./gen_iconv > tables_gen.hpp gen_iconv: gen_iconv.cpp g++ -Wall $^ -o $@ + +clean: + rm -f ./gen_iconv \ No newline at end of file diff --git a/components/to_utf8/gen_iconv.cpp b/components/to_utf8/gen_iconv.cpp index 42e997783..cf4d9ac3f 100644 --- a/components/to_utf8/gen_iconv.cpp +++ b/components/to_utf8/gen_iconv.cpp @@ -74,13 +74,28 @@ int write_table(const std::string &charset, const std::string &tableName) // Finish table cout << "};\n"; + + return 0; } int main() { cout << hex; + // Write header guard + cout << "#ifndef COMPONENTS_TOUTF8_TABLE_GEN_H\n#define COMPONENTS_TOUTF8_TABLE_GEN_H\n\n"; + + // Write namespace + cout << "namespace ToUTF8\n{\n\n"; + // English write_table("WINDOWS-1252", "windows_1252"); + + // Close namespace + cout << "\n}\n\n"; + + // Close header guard + cout << "#endif\n\n"; + return 0; } diff --git a/components/to_utf8/tables_gen.hpp b/components/to_utf8/tables_gen.hpp index 55a06cd94..a45d5d181 100644 --- a/components/to_utf8/tables_gen.hpp +++ b/components/to_utf8/tables_gen.hpp @@ -1,3 +1,9 @@ +#ifndef COMPONENTS_TOUTF8_TABLE_GEN_H +#define COMPONENTS_TOUTF8_TABLE_GEN_H + +namespace ToUTF8 +{ + static char windows_1252[] = { 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, @@ -257,3 +263,8 @@ static char windows_1252[] = 0x2, 0xc3, 0xbe, 0x0, 0x0, 0x0, 0x2, 0xc3, 0xbf, 0x0, 0x0, 0x0 }; + +} + +#endif + diff --git a/components/to_utf8/to_utf8.cpp b/components/to_utf8/to_utf8.cpp index 6f6933143..5f38313aa 100644 --- a/components/to_utf8/to_utf8.cpp +++ b/components/to_utf8/to_utf8.cpp @@ -131,7 +131,7 @@ std::string ToUTF8::getUtf8(ToUTF8::FromType from) // Pick translation array const char *arr; if(from == ToUTF8::WINDOWS_1252) - arr = windows_1252; + arr = ToUTF8::windows_1252; else assert(0);