/** * Casts one fixed-width char type into another. * * @param Ch The character to convert. * @return The converted character. */ template <typename To, typename From> FORCEINLINE To CharCast(From Ch) { To Result; FPlatformString::Convert(&Result, 1, &Ch, 1, (To)UNICODE_BOGUS_CHAR_CODEPOINT); return Result; }
/** * Converts the [Src, Src+SrcSize) string range from SourceChar to DestChar and writes it to the [Dest, Dest+DestSize) range. * The Src range should contain a null terminator if a null terminator is required in the output. * If the Dest range is not big enough to hold the converted output, NULL is returned. In this case, nothing should be assumed about the contents of Dest. * * @param Dest The start of the destination buffer. * @param DestSize The size of the destination buffer. * @param Src The start of the string to convert. * @param SrcSize The number of Src elements to convert. * @param BogusChar The char to use when the conversion process encounters a character it cannot convert. * @return A pointer to one past the last-written element. */ template <typename SourceEncoding, typename DestEncoding> static FORCEINLINE typename TEnableIf< // This overload should be called when SourceEncoding and DestEncoding are 'compatible', i.e. they're the same type or equivalent (e.g. like UCS2CHAR and WIDECHAR are on Windows). TAreEncodingsCompatible<SourceEncoding, DestEncoding>::Value, DestEncoding* >::Type Convert(DestEncoding* Dest, int32 DestSize, const SourceEncoding* Src, int32 SrcSize, DestEncoding BogusChar = (DestEncoding)'?') { if (DestSize < SrcSize) returnnullptr;
/** * Tests whether a particular character can be converted to the destination encoding. * * @param Ch The character to test. * @return True if Ch can be encoded as a DestEncoding. */ template <typename DestEncoding, typename SourceEncoding> staticboolCanConvertChar(SourceEncoding Ch) { returnIsValidChar(Ch) && (SourceEncoding)(DestEncoding)Ch == Ch && IsValidChar((DestEncoding)Ch); }