@@ -48,7 +48,7 @@ const bool dirDown = false;
4848#endif
4949
5050
51- #define NPP_INTERNAL_FUCTION_STR L" Notepad++::InternalFunction"
51+ #define NPP_INTERNAL_FUNCTION_STR L" Notepad++::InternalFunction"
5252
5353
5454std::wstring folderBrowser (HWND parent, const std::wstring & title = L" " , int outputCtrlID = 0 , const wchar_t *defaultStr = NULL );
@@ -87,17 +87,18 @@ class WcharMbcsConvertor final
8787 return instance;
8888 }
8989
90- const wchar_t * char2wchar (const char *mbStr, size_t codepage, int lenMbcs =-1 , int * pLenOut=NULL , int * pBytesNotProcessed=NULL );
91- const wchar_t * char2wchar (const char *mbcs2Convert, size_t codepage, intptr_t * mstart, intptr_t * mend);
92- const char * wchar2char (const wchar_t *wcStr, size_t codepage, int lenIn = -1 , int * pLenOut = NULL );
93- const char * wchar2char (const wchar_t *wcStr, size_t codepage, intptr_t * mstart, intptr_t * mend);
90+ const wchar_t * char2wchar (const char * mbStr, size_t codepage, int lenMbcs = -1 , int * pLenOut = NULL , int * pBytesNotProcessed = NULL );
91+ const wchar_t * char2wchar (const char * mbcs2Convert, size_t codepage, intptr_t * mstart, intptr_t * mend, int len = 0 );
92+ size_t getSizeW () { return _wideCharStr.size (); };
93+ const char * wchar2char (const wchar_t * wcStr, size_t codepage, int lenIn = -1 , int * pLenOut = NULL );
94+ const char * wchar2char (const wchar_t * wcStr, size_t codepage, intptr_t * mstart, intptr_t * mend, int lenIn = 0 , int * lenOut = nullptr );
95+ size_t getSizeA () { return _multiByteStr.size (); };
9496
95- const char * encode (UINT fromCodepage, UINT toCodepage, const char *txt2Encode, int lenIn = -1 , int * pLenOut=NULL , int * pBytesNotProcessed=NULL )
96- {
97+ const char * encode (UINT fromCodepage, UINT toCodepage, const char * txt2Encode, int lenIn = -1 , int * pLenOut = NULL , int * pBytesNotProcessed = NULL ) {
9798 int lenWc = 0 ;
98- const wchar_t * strW = char2wchar (txt2Encode, fromCodepage, lenIn, &lenWc, pBytesNotProcessed);
99- return wchar2char (strW, toCodepage, lenWc, pLenOut);
100- }
99+ const wchar_t * strW = char2wchar (txt2Encode, fromCodepage, lenIn, &lenWc, pBytesNotProcessed);
100+ return wchar2char (strW, toCodepage, lenWc, pLenOut);
101+ }
101102
102103protected:
103104 WcharMbcsConvertor () = default ;
@@ -112,46 +113,46 @@ class WcharMbcsConvertor final
112113 WcharMbcsConvertor (WcharMbcsConvertor&&) = delete ;
113114 WcharMbcsConvertor& operator = (WcharMbcsConvertor&&) = delete ;
114115
115- template <class T >
116- class StringBuffer final
116+ template <class T > class StringBuffer final
117117 {
118118 public:
119119 ~StringBuffer () { if (_allocLen) delete[] _str; }
120120
121- void sizeTo (size_t size)
122- {
123- if (_allocLen < size)
121+ void sizeTo (size_t size) {
122+ if (_allocLen < size + 1 )
124123 {
125124 if (_allocLen)
126125 delete[] _str;
127- _allocLen = std::max<size_t >(size, initSize);
128- _str = new T[_allocLen];
126+ _allocLen = std::max<size_t >(size + 1 , initSize);
127+ _str = new T[_allocLen]{} ;
129128 }
129+ _dataLen = size;
130130 }
131131
132- void empty ()
133- {
132+ void empty () {
134133 static T nullStr = 0 ; // routines may return an empty string, with null terminator, without allocating memory; a pointer to this null character will be returned in that case
135134 if (_allocLen == 0 )
136135 _str = &nullStr;
137136 else
138137 _str[0 ] = 0 ;
138+ _dataLen = 0 ;
139139 }
140140
141+ size_t size () const { return _dataLen; }
141142 operator T* () { return _str; }
142143 operator const T* () const { return _str; }
143144
144145 protected:
145146 static const int initSize = 1024 ;
146147 size_t _allocLen = 0 ;
148+ size_t _dataLen = 0 ;
147149 T* _str = nullptr ;
148150 };
149151
150152 StringBuffer<char > _multiByteStr;
151153 StringBuffer<wchar_t > _wideCharStr;
152154};
153155
154-
155156#define REBARBAND_SIZE sizeof (REBARBANDINFO)
156157
157158std::wstring pathRemoveFileSpec (std::wstring & path);
0 commit comments