1 /* Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 * Use of this source code is governed by a BSD-style license that can be 3 * found in the LICENSE file. 4 */ 5 #ifndef PPAPI_C_DEV_PPB_CHAR_SET_DEV_H_ 6 #define PPAPI_C_DEV_PPB_CHAR_SET_DEV_H_ 7 8 #include "ppapi/c/pp_instance.h" 9 #include "ppapi/c/pp_macros.h" 10 #include "ppapi/c/pp_stdint.h" 11 #include "ppapi/c/pp_var.h" 12 13 #define PPB_CHAR_SET_DEV_INTERFACE_0_4 "PPB_CharSet(Dev);0.4" 14 #define PPB_CHAR_SET_DEV_INTERFACE PPB_CHAR_SET_DEV_INTERFACE_0_4 15 16 // Specifies the error behavior for the character set conversion functions. 17 // This will affect two cases: where the input is not encoded correctly, and 18 // when the requested character can not be converted to the destination 19 // character set. 20 enum PP_CharSet_ConversionError { 21 // Causes the entire conversion to fail if an error is encountered. The 22 // conversion function will return NULL. 23 PP_CHARSET_CONVERSIONERROR_FAIL, 24 25 // Silently skips over errors. Unrepresentable characters and input encoding 26 // errors will be removed from the output. 27 PP_CHARSET_CONVERSIONERROR_SKIP, 28 29 // Replaces the error or unrepresentable character with a substitution 30 // character. When converting to a Unicode character set (UTF-8 or UTF-16) 31 // it will use the unicode "substitution character" U+FFFD. When converting 32 // to another character set, the character will be charset-specific. For 33 // many languages this will be the representation of the '?' character. 34 PP_CHARSET_CONVERSIONERROR_SUBSTITUTE 35 }; 36 PP_COMPILE_ASSERT_ENUM_SIZE_IN_BYTES(PP_CharSet_ConversionError, 4); 37 38 struct PPB_CharSet_Dev_0_4 { 39 // Converts the UTF-16 string pointed to in |*utf16| to an 8-bit string in the 40 // specified code page. |utf16_len| is measured in UTF-16 units, not bytes. 41 // This value may not be NULL. 42 // 43 // The return value is a NULL-terminated 8-bit string corresponding to the 44 // new character set, or NULL on failure. THIS STRING MUST BE FREED USING 45 // PPB_Core::MemFree(). The length of the returned string, not including the 46 // terminating NULL, will be placed into *output_length. When there is no 47 // error, the result will always be non-NULL, even if the output is 0-length. 48 // In this case, it will only contain the terminator. You must still call 49 // MemFree any time the return value is non-NULL. 50 // 51 // This function will return NULL if there was an error converting the string 52 // and you requested PP_CHARSET_CONVERSIONERROR_FAIL, or the output character 53 // set was unknown. 54 char* (*UTF16ToCharSet)(PP_Instance instance, 55 const uint16_t* utf16, uint32_t utf16_len, 56 const char* output_char_set, 57 enum PP_CharSet_ConversionError on_error, 58 uint32_t* output_length); 59 60 // Same as UTF16ToCharSet except converts in the other direction. The input 61 // is in the given charset, and the |input_len| is the number of bytes in 62 // the |input| string. |*output_length| is the number of 16-bit values in 63 // the output not counting the terminating NULL. 64 // 65 // Since UTF16 can represent every Unicode character, the only time the 66 // replacement character will be used is if the encoding in the input string 67 // is incorrect. 68 uint16_t* (*CharSetToUTF16)(PP_Instance instance, 69 const char* input, uint32_t input_len, 70 const char* input_char_set, 71 enum PP_CharSet_ConversionError on_error, 72 uint32_t* output_length); 73 74 // Returns a string var representing the current multi-byte character set of 75 // the current system. 76 // 77 // WARNING: You really shouldn't be using this function unless you're dealing 78 // with legacy data. You should be using UTF-8 or UTF-16 and you don't have 79 // to worry about the character sets. 80 struct PP_Var (*GetDefaultCharSet)(PP_Instance instance); 81 }; 82 83 typedef struct PPB_CharSet_Dev_0_4 PPB_CharSet_Dev; 84 85 #endif /* PPAPI_C_DEV_PPB_CHAR_SET_DEV_H_ */ 86