Commit f514d7d71e2aa288eef6952165ea826f95496091

Authored by Jarryd Beck
1 parent 0cd24a7e

start converting to String for Unicode

Showing 1 changed file with 45 additions and 12 deletions
src/cxxopts.hpp
@@ -34,6 +34,37 @@ THE SOFTWARE. @@ -34,6 +34,37 @@ THE SOFTWARE.
34 #include <string> 34 #include <string>
35 #include <vector> 35 #include <vector>
36 36
  37 +#ifdef CXXOPTS_USE_UNICODE
  38 +#include <unistr.h>
  39 +
  40 +namespace cxxopts
  41 +{
  42 + typedef icu::UnicodeString String;
  43 +
  44 + inline
  45 + String
  46 + toLocalString(std::string s)
  47 + {
  48 + return icu::UnicodeString::fromUTF8(s);
  49 + }
  50 +}
  51 +
  52 +#else
  53 +
  54 +namespace cxxopts
  55 +{
  56 + typedef std::string String;
  57 +
  58 + inline
  59 + String
  60 + toLocalString(std::string s)
  61 + {
  62 + return std::move(s);
  63 + }
  64 +}
  65 +
  66 +#endif
  67 +
37 namespace cxxopts 68 namespace cxxopts
38 { 69 {
39 class Value 70 class Value
@@ -284,7 +315,7 @@ namespace cxxopts @@ -284,7 +315,7 @@ namespace cxxopts
284 public: 315 public:
285 OptionDetails 316 OptionDetails
286 ( 317 (
287 - const std::string& description, 318 + const String& description,
288 std::shared_ptr<const Value> value 319 std::shared_ptr<const Value> value
289 ) 320 )
290 : m_desc(description) 321 : m_desc(description)
@@ -293,7 +324,7 @@ namespace cxxopts @@ -293,7 +324,7 @@ namespace cxxopts
293 { 324 {
294 } 325 }
295 326
296 - const std::string& 327 + const String&
297 description() const 328 description() const
298 { 329 {
299 return m_desc; 330 return m_desc;
@@ -326,7 +357,7 @@ namespace cxxopts @@ -326,7 +357,7 @@ namespace cxxopts
326 } 357 }
327 358
328 private: 359 private:
329 - std::string m_desc; 360 + String m_desc;
330 std::shared_ptr<const Value> m_value; 361 std::shared_ptr<const Value> m_value;
331 int m_count; 362 int m_count;
332 }; 363 };
@@ -335,7 +366,7 @@ namespace cxxopts @@ -335,7 +366,7 @@ namespace cxxopts
335 { 366 {
336 std::string s; 367 std::string s;
337 std::string l; 368 std::string l;
338 - std::string desc; 369 + String desc;
339 bool has_arg; 370 bool has_arg;
340 }; 371 };
341 372
@@ -371,7 +402,7 @@ namespace cxxopts @@ -371,7 +402,7 @@ namespace cxxopts
371 const std::string& group, 402 const std::string& group,
372 const std::string& s, 403 const std::string& s,
373 const std::string& l, 404 const std::string& l,
374 - const std::string& desc, 405 + std::string desc,
375 std::shared_ptr<const Value> value 406 std::shared_ptr<const Value> value
376 ); 407 );
377 408
@@ -502,7 +533,7 @@ namespace cxxopts @@ -502,7 +533,7 @@ namespace cxxopts
502 std::basic_regex<char> option_specifier 533 std::basic_regex<char> option_specifier
503 ("(([a-zA-Z]),)?([a-zA-Z0-9][-_a-zA-Z0-9]+)"); 534 ("(([a-zA-Z]),)?([a-zA-Z0-9][-_a-zA-Z0-9]+)");
504 535
505 - std::string 536 + String
506 format_option 537 format_option
507 ( 538 (
508 const std::string& s, 539 const std::string& s,
@@ -534,15 +565,15 @@ namespace cxxopts @@ -534,15 +565,15 @@ namespace cxxopts
534 return result; 565 return result;
535 } 566 }
536 567
537 - std::string 568 + String
538 format_description 569 format_description
539 ( 570 (
540 - const std::string& text, 571 + const String& text,
541 int start, 572 int start,
542 int width 573 int width
543 ) 574 )
544 { 575 {
545 - std::string result; 576 + String result;
546 577
547 auto current = text.begin(); 578 auto current = text.begin();
548 auto startLine = current; 579 auto startLine = current;
@@ -808,11 +839,12 @@ Options::add_option @@ -808,11 +839,12 @@ Options::add_option
808 const std::string& group, 839 const std::string& group,
809 const std::string& s, 840 const std::string& s,
810 const std::string& l, 841 const std::string& l,
811 - const std::string& desc, 842 + std::string desc,
812 std::shared_ptr<const Value> value 843 std::shared_ptr<const Value> value
813 ) 844 )
814 { 845 {
815 - auto option = std::make_shared<OptionDetails>(desc, value); 846 + auto stringDesc = toLocalString(std::move(desc));
  847 + auto option = std::make_shared<OptionDetails>(stringDesc, value);
816 848
817 if (s.size() > 0) 849 if (s.size() > 0)
818 { 850 {
@@ -826,7 +858,8 @@ Options::add_option @@ -826,7 +858,8 @@ Options::add_option
826 858
827 //add the help details 859 //add the help details
828 auto& options = m_help[group]; 860 auto& options = m_help[group];
829 - options.options.emplace_back(HelpOptionDetails{s, l, desc, value->has_arg()}); 861 + options.options.
  862 + emplace_back(HelpOptionDetails{s, l, stringDesc, value->has_arg()});
830 } 863 }
831 864
832 void 865 void