src/XercesStringConvertor.h
branchv_0
changeset 8 14e14a5db027
parent 6 be83e0f457a8
child 15 177321664baf
equal deleted inserted replaced
7:85741b08db48 8:14e14a5db027
    36 private:
    36 private:
    37 	wstring_convert<codecvt_utf8<wchar_t>> convertor; // TODO: support also other encodings.
    37 	wstring_convert<codecvt_utf8<wchar_t>> convertor; // TODO: support also other encodings.
    38 
    38 
    39 public:
    39 public:
    40 
    40 
    41 	string_t toString(const XMLCh * const chars) {
    41 	string_t toString(const XMLCh* const chars) {
    42 		// XMLCh = char16_t
    42 		// XMLCh = char16_t
    43 		// „All XML data is handled within Xerces-C++ as strings of XMLCh characters. Regardless of the size of the type chosen, the data stored in variables of type XMLCh will always be utf-16 encoded values.“
    43 		// „All XML data is handled within Xerces-C++ as strings of XMLCh characters. Regardless of the size of the type chosen, the data stored in variables of type XMLCh will always be utf-16 encoded values.“
    44 		// see https://xerces.apache.org/xerces-c/program-others-3.html
    44 		// see https://xerces.apache.org/xerces-c/program-others-3.html
    45 		// other solution (depends on boost): https://flylib.com/books/en/2.131.1/working_with_xerces_strings.html
    45 		// other solution (depends on boost): https://flylib.com/books/en/2.131.1/working_with_xerces_strings.html
    46 
    46 
    48 		char* x = XMLString::transcode(chars);
    48 		char* x = XMLString::transcode(chars);
    49 		string s = string(x);
    49 		string s = string(x);
    50 		XMLString::release(&x);
    50 		XMLString::release(&x);
    51 		return convertor.from_bytes(s);
    51 		return convertor.from_bytes(s);
    52 	}
    52 	}
       
    53 
       
    54 	/**
       
    55 	 * @param string
       
    56 	 * @return Xerces string. Must be released manually after use, see XMLString::release().
       
    57 	 */
       
    58 	XMLCh* toXercesString(string_t string) {
       
    59 		return XMLString::transcode(convertor.to_bytes(string).c_str());
       
    60 	}
    53 };
    61 };
    54 
    62 
    55 }
    63 }
    56 }
    64 }
    57 }
    65 }