diff options
author | Pavel Labath <pavelo@centrum.sk> | 2011-06-16 20:07:27 (GMT) |
---|---|---|
committer | Paul Tagliamonte <paultag@fluxbox.org> | 2012-04-07 02:10:41 (GMT) |
commit | 7376858970d89e034af50c75f752d2cdde1b80f9 (patch) | |
tree | f70c5559230488e74c21331330810bdaf828a389 /src/FbTk/ResTraits.hh | |
parent | 3b1abf8f8f812a9e97cc1b7f6fe95a1bf07d3246 (diff) | |
download | fluxbox_paul-7376858970d89e034af50c75f752d2cdde1b80f9.zip fluxbox_paul-7376858970d89e034af50c75f752d2cdde1b80f9.tar.bz2 |
Add LocaleStringTraits resource class
for resources which need to work with localised strings.
Diffstat (limited to 'src/FbTk/ResTraits.hh')
-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)) ); |