diff options
author | Pavel Labath <pavelo@centrum.sk> | 2011-06-16 20:07:27 (GMT) |
---|---|---|
committer | Pavel Labath <pavelo@centrum.sk> | 2011-11-01 09:57:19 (GMT) |
commit | 7d0fad978e7f6026ea8bbf076df45442862e8086 (patch) | |
tree | 581e9e307ac4c7838652a2b897582722768ef3c1 /src | |
parent | e3feca08ce0f6753f7e71ccb9088cf9003d41fc2 (diff) | |
download | fluxbox_paul-7d0fad978e7f6026ea8bbf076df45442862e8086.zip fluxbox_paul-7d0fad978e7f6026ea8bbf076df45442862e8086.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)) ); |