start converting to String for Unicode

This commit is contained in:
Jarryd Beck 2014-10-27 13:30:22 +11:00
parent 0cd24a7e6b
commit f514d7d71e

View File

@ -34,6 +34,37 @@ THE SOFTWARE.
#include <string> #include <string>
#include <vector> #include <vector>
#ifdef CXXOPTS_USE_UNICODE
#include <unistr.h>
namespace cxxopts
{
typedef icu::UnicodeString String;
inline
String
toLocalString(std::string s)
{
return icu::UnicodeString::fromUTF8(s);
}
}
#else
namespace cxxopts
{
typedef std::string String;
inline
String
toLocalString(std::string s)
{
return std::move(s);
}
}
#endif
namespace cxxopts namespace cxxopts
{ {
class Value class Value
@ -284,7 +315,7 @@ namespace cxxopts
public: public:
OptionDetails OptionDetails
( (
const std::string& description, const String& description,
std::shared_ptr<const Value> value std::shared_ptr<const Value> value
) )
: m_desc(description) : m_desc(description)
@ -293,7 +324,7 @@ namespace cxxopts
{ {
} }
const std::string& const String&
description() const description() const
{ {
return m_desc; return m_desc;
@ -326,7 +357,7 @@ namespace cxxopts
} }
private: private:
std::string m_desc; String m_desc;
std::shared_ptr<const Value> m_value; std::shared_ptr<const Value> m_value;
int m_count; int m_count;
}; };
@ -335,7 +366,7 @@ namespace cxxopts
{ {
std::string s; std::string s;
std::string l; std::string l;
std::string desc; String desc;
bool has_arg; bool has_arg;
}; };
@ -371,7 +402,7 @@ namespace cxxopts
const std::string& group, const std::string& group,
const std::string& s, const std::string& s,
const std::string& l, const std::string& l,
const std::string& desc, std::string desc,
std::shared_ptr<const Value> value std::shared_ptr<const Value> value
); );
@ -502,7 +533,7 @@ namespace cxxopts
std::basic_regex<char> option_specifier std::basic_regex<char> option_specifier
("(([a-zA-Z]),)?([a-zA-Z0-9][-_a-zA-Z0-9]+)"); ("(([a-zA-Z]),)?([a-zA-Z0-9][-_a-zA-Z0-9]+)");
std::string String
format_option format_option
( (
const std::string& s, const std::string& s,
@ -534,15 +565,15 @@ namespace cxxopts
return result; return result;
} }
std::string String
format_description format_description
( (
const std::string& text, const String& text,
int start, int start,
int width int width
) )
{ {
std::string result; String result;
auto current = text.begin(); auto current = text.begin();
auto startLine = current; auto startLine = current;
@ -808,11 +839,12 @@ Options::add_option
const std::string& group, const std::string& group,
const std::string& s, const std::string& s,
const std::string& l, const std::string& l,
const std::string& desc, std::string desc,
std::shared_ptr<const Value> value std::shared_ptr<const Value> value
) )
{ {
auto option = std::make_shared<OptionDetails>(desc, value); auto stringDesc = toLocalString(std::move(desc));
auto option = std::make_shared<OptionDetails>(stringDesc, value);
if (s.size() > 0) if (s.size() > 0)
{ {
@ -826,7 +858,8 @@ Options::add_option
//add the help details //add the help details
auto& options = m_help[group]; auto& options = m_help[group];
options.options.emplace_back(HelpOptionDetails{s, l, desc, value->has_arg()}); options.options.
emplace_back(HelpOptionDetails{s, l, stringDesc, value->has_arg()});
} }
void void