diff options
author | Pavel Labath <pavelo@centrum.sk> | 2011-06-16 20:07:27 (GMT) |
---|---|---|
committer | Pavel Labath <pavelo@centrum.sk> | 2013-02-16 23:54:31 (GMT) |
commit | f7ab4aaba8832a5e5073fb14f6b4d8abfbb7750f (patch) | |
tree | ce802eb6fc234ab33caca02b0226409b0ad08ef1 /src/FbTk | |
parent | 9f2c3883b7cf08a5f9d311fd8f7fc317574b605b (diff) | |
download | fluxbox_pavel-f7ab4aaba8832a5e5073fb14f6b4d8abfbb7750f.zip fluxbox_pavel-f7ab4aaba8832a5e5073fb14f6b4d8abfbb7750f.tar.bz2 |
Add LocaleStringTraits resource class
for resources which need to work with localised strings.
Diffstat (limited to 'src/FbTk')
-rw-r--r-- | src/FbTk/ResTraits.hh | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/src/FbTk/ResTraits.hh b/src/FbTk/ResTraits.hh index 2ea5986..3ee4464 100644 --- a/src/FbTk/ResTraits.hh +++ b/src/FbTk/ResTraits.hh | |||
@@ -25,6 +25,7 @@ | |||
25 | #include <stdexcept> | 25 | #include <stdexcept> |
26 | #include <vector> | 26 | #include <vector> |
27 | 27 | ||
28 | #include "FbString.hh" | ||
28 | #include "Luamm.hh" | 29 | #include "Luamm.hh" |
29 | #include "StringUtil.hh" | 30 | #include "StringUtil.hh" |
30 | 31 | ||
@@ -65,14 +66,30 @@ struct IntTraits { | |||
65 | 66 | ||
66 | struct StringTraits { | 67 | struct StringTraits { |
67 | typedef std::string Type; | 68 | typedef std::string Type; |
68 | static std::string toString(const std::string &x) { return x; } | 69 | static const std::string &toString(const std::string &x) { return x; } |
69 | static void toLua(const std::string &x, lua::state &l) { l.pushstring(x); } | 70 | static void toLua(const std::string &x, lua::state &l) { l.pushstring(x); } |
70 | static std::string fromString(const std::string &x) { return x; } | 71 | static const std::string &fromString(const std::string &x) { return x; } |
71 | 72 | ||
72 | static std::string fromLua(lua::state &l) { | 73 | static std::string fromLua(lua::state &l) { |
73 | lua::stack_sentry s(l, -1); | 74 | lua::stack_sentry s(l, -1); |
74 | 75 | ||
75 | if(l.isstring(-1) || l.isnumber(-1)) | 76 | if(l.isstring(-1) || l.isnumber(-1)) |
77 | return l.tostring(-1); | ||
78 | throw ConversionError( std::string("Cannot convert to string from lua type ") | ||
79 | + l.type_name(l.type(-1)) ); | ||
80 | } | ||
81 | }; | ||
82 | |||
83 | struct FbStringTraits { | ||
84 | typedef FbString Type; | ||
85 | static std::string toString(const FbString &x) { return FbStringUtil::FbStrToLocale(x); } | ||
86 | static void toLua(const FbString &x, lua::state &l) { l.pushstring(toString(x)); } | ||
87 | static FbString fromString(const std::string &x) { return FbStringUtil::LocaleStrToFb(x); } | ||
88 | |||
89 | static FbString fromLua(lua::state &l) { | ||
90 | lua::stack_sentry s(l, -1); | ||
91 | |||
92 | if(l.isstring(-1) || l.isnumber(-1)) | ||
76 | return fromString(l.tostring(-1)); | 93 | return fromString(l.tostring(-1)); |
77 | throw ConversionError( std::string("Cannot convert to string from lua type ") | 94 | throw ConversionError( std::string("Cannot convert to string from lua type ") |
78 | + l.type_name(l.type(-1)) ); | 95 | + l.type_name(l.type(-1)) ); |