diff options
author | Pavel Labath <pavelo@centrum.sk> | 2011-06-16 20:07:27 (GMT) |
---|---|---|
committer | Pavel Labath <pavelo@centrum.sk> | 2011-06-16 20:37:47 (GMT) |
commit | 1fee50374c21b92e77c63a179095174504d74a87 (patch) | |
tree | c82f79773c0ef01807eeecb16c88c97f56423156 /src | |
parent | abe30f34b20970420b09a3b02ea98444d39afc94 (diff) | |
download | fluxbox_pavel-1fee50374c21b92e77c63a179095174504d74a87.zip fluxbox_pavel-1fee50374c21b92e77c63a179095174504d74a87.tar.bz2 |
Add LocaleStringTraits resource class
for resources which need to work with localised strings.
Diffstat (limited to 'src')
-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)) ); |