MCPcopy Create free account
hub / github.com/brofield/simpleini / SI_ConvertA

Class SI_ConvertA

SimpleIni.h:2870–2970  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2868 * Null conversion class for MBCS/UTF-8 to char (or equivalent).
2869 */
2870template <class SI_CHAR> class SI_ConvertA {
2871 bool m_bStoreIsUtf8;
2872
2873protected:
2874 SI_ConvertA() {}
2875
2876public:
2877 SI_ConvertA(bool a_bStoreIsUtf8) : m_bStoreIsUtf8(a_bStoreIsUtf8) {}
2878
2879 /* copy and assignment */
2880 SI_ConvertA(const SI_ConvertA &rhs) { operator=(rhs); }
2881 SI_ConvertA &operator=(const SI_ConvertA &rhs) {
2882 m_bStoreIsUtf8 = rhs.m_bStoreIsUtf8;
2883 return *this;
2884 }
2885
2886 /** Calculate the number of SI_CHAR required for converting the input
2887 * from the storage format. The storage format is always UTF-8 or MBCS.
2888 *
2889 * @param a_pInputData Data in storage format to be converted to SI_CHAR.
2890 * @param a_uInputDataLen Length of storage format data in bytes. This
2891 * must be the actual length of the data, including
2892 * NULL byte if NULL terminated string is required.
2893 * @return Number of SI_CHAR required by the string when
2894 * converted. If there are embedded NULL bytes in the
2895 * input data, only the string up and not including
2896 * the NULL byte will be converted.
2897 * @return -1 cast to size_t on a conversion error.
2898 */
2899 size_t SizeFromStore(const char *a_pInputData, size_t a_uInputDataLen) {
2900 (void)a_pInputData;
2901 SI_ASSERT(a_uInputDataLen != (size_t)-1);
2902
2903 // ASCII/MBCS/UTF-8 needs no conversion
2904 return a_uInputDataLen;
2905 }
2906
2907 /** Convert the input string from the storage format to SI_CHAR.
2908 * The storage format is always UTF-8 or MBCS.
2909 *
2910 * @param a_pInputData Data in storage format to be converted to SI_CHAR.
2911 * @param a_uInputDataLen Length of storage format data in bytes. This
2912 * must be the actual length of the data, including
2913 * NULL byte if NULL terminated string is required.
2914 * @param a_pOutputData Pointer to the output buffer to received the
2915 * converted data.
2916 * @param a_uOutputDataSize Size of the output buffer in SI_CHAR.
2917 * @return true if all of the input data was successfully
2918 * converted.
2919 */
2920 bool ConvertFromStore(const char *a_pInputData, size_t a_uInputDataLen,
2921 SI_CHAR *a_pOutputData, size_t a_uOutputDataSize) {
2922 // ASCII/MBCS/UTF-8 needs no conversion
2923 if (a_uInputDataLen > a_uOutputDataSize) {
2924 return false;
2925 }
2926 memcpy(a_pOutputData, a_pInputData, a_uInputDataLen);
2927 return true;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected