use UTF-8 for string representation

This commit is contained in:
Jinhao
2015-12-15 21:46:24 +08:00
parent 8fc84938bf
commit c260eebbc3
11 changed files with 178 additions and 165 deletions

View File

@@ -22,7 +22,7 @@ namespace detail
Window window;
int x;
int y;
std::vector<nana::string> * files;
std::vector<std::string> * files;
}mouse_drop;
}u;
};

View File

@@ -70,7 +70,7 @@ namespace detail
struct font_tag
{
nana::string name;
std::string name;
unsigned height;
unsigned weight;
bool italic;

View File

@@ -131,7 +131,7 @@ namespace nana{ namespace widgets
struct keywords;
class keyword_parser;
public:
using char_type = ::nana::char_t;
using char_type = wchar_t;
using size_type = textbase<char_type>::size_type;
using string_type = textbase<char_type>::string_type;
@@ -152,10 +152,10 @@ namespace nana{ namespace widgets
text_editor(window, graph_reference, const text_editor_scheme*);
~text_editor();
void set_highlight(const std::string& name, const ::nana::color&, const ::nana::color&);
void erase_highlight(const std::string& name);
void set_keyword(const ::nana::string& kw, const std::string& name, bool case_sensitive, bool whole_word_matched);
void erase_keyword(const ::nana::string& kw);
void set_highlight(const ::std::string& name, const ::nana::color&, const ::nana::color&);
void erase_highlight(const ::std::string& name);
void set_keyword(const ::std::wstring& kw, const std::string& name, bool case_sensitive, bool whole_word_matched);
void erase_keyword(const ::std::wstring& kw);
void set_accept(std::function<bool(char_type)>);
void set_accept(accepts);
@@ -164,7 +164,7 @@ namespace nana{ namespace widgets
void typeface_changed();
void indent(bool, std::function<nana::string()> generator);
void indent(bool, std::function<std::string()> generator);
void set_event(event_interface*);
/// Determine whether the text_editor is line wrapped.
@@ -174,7 +174,7 @@ namespace nana{ namespace widgets
void border_renderer(std::function<void(graph_reference, const ::nana::color& bgcolor)>);
bool load(const nana::char_t*);
bool load(const char*);
/// Sets the text area.
/// @return true if the area is changed with the new value.
@@ -183,7 +183,7 @@ namespace nana{ namespace widgets
/// Returns the text area
rectangle text_area(bool including_scroll) const;
bool tip_string(nana::string&&);
bool tip_string(::std::string&&);
const attributes & attr() const;
bool multi_lines(bool);
@@ -201,9 +201,9 @@ namespace nana{ namespace widgets
unsigned line_height() const;
unsigned screen_lines() const;
bool getline(std::size_t pos, nana::string&) const;
void text(nana::string);
nana::string text() const;
bool getline(std::size_t pos, ::std::wstring&) const;
void text(std::wstring);
std::wstring text() const;
/// Sets caret position through text coordinate.
void move_caret(const upoint&);
@@ -233,8 +233,8 @@ namespace nana{ namespace widgets
void draw_corner();
void render(bool focused);
public:
void put(nana::string);
void put(nana::char_t);
void put(std::wstring);
void put(wchar_t);
void copy() const;
void cut();
void paste();
@@ -264,11 +264,11 @@ namespace nana{ namespace widgets
::nana::size _m_text_area() const;
void _m_get_scrollbar_size();
void _m_reset();
::nana::upoint _m_put(nana::string);
::nana::upoint _m_put(::std::wstring);
::nana::upoint _m_erase_select();
bool _m_make_select_string(nana::string&) const;
static bool _m_resolve_text(const nana::string&, std::vector<std::pair<std::size_t, std::size_t>> & lines);
bool _m_make_select_string(::std::wstring&) const;
static bool _m_resolve_text(const ::std::wstring&, std::vector<std::pair<std::size_t, std::size_t>> & lines);
bool _m_cancel_select(int align);
unsigned _m_tabs_pixels(size_type tabs) const;
@@ -283,10 +283,10 @@ namespace nana{ namespace widgets
/// Returns the right/bottom point of text area.
int _m_end_pos(bool right) const;
void _m_draw_parse_string(const keyword_parser&, bool rtl, ::nana::point pos, const ::nana::color& fgcolor, const ::nana::char_t*, std::size_t len) const;
void _m_draw_parse_string(const keyword_parser&, bool rtl, ::nana::point pos, const ::nana::color& fgcolor, const wchar_t*, std::size_t len) const;
//_m_draw_string
//@brief: Draw a line of string
void _m_draw_string(int top, const ::nana::color&, const nana::upoint& str_pos, const nana::string&, bool if_mask) const;
void _m_draw_string(int top, const ::nana::color&, const nana::upoint& str_pos, const ::std::wstring&, bool if_mask) const;
//_m_update_caret_line
//@brief: redraw whole line specified by caret pos.
//@return: true if caret overs the border
@@ -295,8 +295,8 @@ namespace nana{ namespace widgets
void _m_offset_y(int y);
unsigned _m_char_by_pixels(const nana::char_t*, std::size_t len, unsigned* pxbuf, int str_px, int pixels, bool is_rtl);
unsigned _m_pixels_by_char(const nana::string&, std::size_t pos) const;
unsigned _m_char_by_pixels(const wchar_t*, std::size_t len, unsigned* pxbuf, int str_px, int pixels, bool is_rtl);
unsigned _m_pixels_by_char(const ::std::wstring&, std::size_t pos) const;
void _handle_move_key(const arg_keyboard& arg);
private:
@@ -308,8 +308,8 @@ namespace nana{ namespace widgets
event_interface * event_handler_{ nullptr };
std::unique_ptr<keywords> keywords_;
skeletons::textbase<nana::char_t> textbase_;
nana::char_t mask_char_{0};
skeletons::textbase<wchar_t> textbase_;
wchar_t mask_char_{0};
mutable ext_renderer_tag ext_renderer_;
@@ -318,7 +318,7 @@ namespace nana{ namespace widgets
struct indent_rep
{
bool enabled{ false };
std::function<nana::string()> generator;
std::function<std::string()> generator;
}indent_;
struct attributes
@@ -326,7 +326,7 @@ namespace nana{ namespace widgets
accepts acceptive{ accepts::no_restrict };
std::function<bool(char_type)> pred_acceptive;
nana::string tip_string;
::std::string tip_string;
bool line_wrapped{false};
bool multi_lines{true};

View File

@@ -57,13 +57,12 @@ namespace skeletons
((text_cont_.size() == 1) && (text_cont_[0].empty())));
}
bool load(const nana::char_t* fs)
bool load(const char* file_utf8)
{
if (nullptr == fs)
if (!file_utf8)
return false;
std::string fs_mbs = nana::charset(fs);
std::ifstream ifs(fs_mbs.data());
std::ifstream ifs(to_osmbstr(file_utf8));
if (!ifs)
return false;
@@ -81,7 +80,7 @@ namespace skeletons
if(0xBB == ch && 0xBF == ifs.get())
{
ifs.close();
return load(fs, nana::unicode::utf8);
return load(file_utf8, nana::unicode::utf8);
}
}
else if(0xFF == ch)
@@ -94,11 +93,11 @@ namespace skeletons
if(ifs.get() == 0 && ifs.get() == 0)
{
ifs.close();
return load(fs, nana::unicode::utf32);
return load(file_utf8, nana::unicode::utf32);
}
}
ifs.close();
return load(fs, nana::unicode::utf16);
return load(file_utf8, nana::unicode::utf16);
}
}
else if(0xFE == ch)
@@ -107,7 +106,7 @@ namespace skeletons
{
//UTF16(big-endian)
ifs.close();
return load(fs, nana::unicode::utf16);
return load(file_utf8, nana::unicode::utf16);
}
}
else if(0 == ch)
@@ -119,7 +118,7 @@ namespace skeletons
{
//UTF32(big_endian)
ifs.close();
return load(fs, nana::unicode::utf32);
return load(file_utf8, nana::unicode::utf32);
}
}
}
@@ -143,7 +142,7 @@ namespace skeletons
}
}
_m_saved(fs);
_m_saved(file_utf8);
return true;
}
@@ -175,13 +174,12 @@ namespace skeletons
}
}
bool load(const nana::char_t * fs, nana::unicode encoding)
bool load(const char* file_utf8, nana::unicode encoding)
{
if (nullptr == fs)
if (!file_utf8)
return false;
std::string fs_mbs = nana::charset(fs);
std::ifstream ifs(fs_mbs.data());
std::ifstream ifs(to_osmbstr(file_utf8));
if (!ifs)
return false;
@@ -245,14 +243,13 @@ namespace skeletons
}
}
_m_saved(fs);
_m_saved(file_utf8);
return true;
}
void store(nana::string fs, bool is_unicode, ::nana::unicode encoding) const
void store(std::string fs, bool is_unicode, ::nana::unicode encoding) const
{
std::string fs_mbs = nana::charset(fs);
std::ofstream ofs(fs_mbs.data(), std::ios::binary);
std::ofstream ofs(to_osmbstr(fs), std::ios::binary);
if(ofs && text_cont_.size())
{
std::string last_mbs;
@@ -410,7 +407,7 @@ namespace skeletons
{
std::deque<string_type>().swap(text_cont_);
attr_max_.reset();
_m_saved(nana::string());
_m_saved(std::string());
}
void merge(size_type pos)
@@ -427,7 +424,7 @@ namespace skeletons
}
}
const nana::string& filename() const
const std::string& filename() const
{
return filename_;
}
@@ -489,7 +486,7 @@ namespace skeletons
evt_agent_->first_change();
}
void _m_saved(nana::string && filename) const
void _m_saved(std::string && filename) const
{
if(filename_ != filename)
{
@@ -518,7 +515,7 @@ namespace skeletons
textbase_event_agent_interface* evt_agent_{ nullptr };
mutable bool changed_{ false };
mutable nana::string filename_; //A string for the saved filename.
mutable std::string filename_; //A string for the saved filename.
const string_type nullstr_;
struct attr_max

View File

@@ -97,14 +97,14 @@ namespace nana
void range(std::initializer_list<std::wstring> values);
/// Gets the spined value
::nana::string value() const;
void value(const ::nana::string&);
::std::string value() const;
void value(const ::std::string&);
int to_int() const;
double to_double() const;
/// Sets the modifiers
void modifier(std::wstring prefix, std::wstring suffix);
void modifier(const std::string & prefix_utf8, const std::string& suffix_utf8);
void modifier(std::string prefix_utf8, std::string suffix_utf8);
void modifier(const std::wstring & prefix, const std::wstring& suffix);
private:
native_string_type _m_caption() const throw();
void _m_caption(native_string_type&&);

View File

@@ -126,19 +126,19 @@ namespace nana
textbox(window, const rectangle& = rectangle(), bool visible = true);
/// \brief Loads a text file. When attempt to load a unicode encoded text file, be sure the file have a BOM header.
void load(nana::string file);
void store(nana::string file);
void store(nana::string file, nana::unicode encoding);
void load(std::string file);
void store(std::string file);
void store(std::string file, nana::unicode encoding);
/// Enables/disables the textbox to indent a line. Idents a new line when it is created by pressing enter.
/// @param generator generates text for identing a line. If it is empty, textbox indents the line according to last line.
textbox& indention(bool, std::function<nana::string()> generator = {});
textbox& indention(bool, std::function<std::string()> generator = {});
//A workaround for reset, explicit default constructor syntax, because VC2013 incorrectly treats {} as {0}.
textbox& reset(nana::string = nana::string()); ///< discard the old text and set a new text
textbox& reset(const std::string& = std::string()); ///< discard the old text and set a new text
/// The file of last store operation.
nana::string filename() const;
std::string filename() const;
/// Determine whether the text was edited.
bool edited() const;
@@ -150,7 +150,7 @@ namespace nana
bool saved() const;
/// Read the text from a specified line. It returns true for success.
bool getline(std::size_t pos, nana::string&) const;
bool getline(std::size_t pos, std::string&) const;
/// Gets the caret position
/// Returns true if the caret is in the area of display, false otherwise.
@@ -160,7 +160,7 @@ namespace nana
textbox& caret_pos(const upoint&);
/// Appends an string. If `at_caret` is `true`, the string is inserted at the position of caret, otherwise, it is appended at end of the textbox.
textbox& append(const nana::string& text, bool at_caret);
textbox& append(const std::string& text, bool at_caret);
/// Determine wheter the text is line wrapped.
bool line_wrapped() const;
@@ -197,7 +197,7 @@ namespace nana
void erase_highlight(const std::string& name);
void set_keywords(const std::string& name, bool case_sensitive, bool whole_word_match, std::initializer_list<std::wstring> kw_list);
void set_keywords(const std::string& name, bool case_sensitive, bool whole_word_match, std::initializer_list<std::string> kw_list_utf8);
void erase_keyword(const nana::string& kw);
void erase_keyword(const std::string& kw);
/// Returns the text position of each line that currently displays on screen.
text_positions text_position() const;