mirror of
https://github.com/SFML/SFML.git
synced 2024-11-25 04:41:05 +08:00
Added conversions from/to latin-1 (ISO-5589-1) in sf::Utf classes
git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1758 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
parent
23d0ee8550
commit
74ebd1a50b
@ -152,6 +152,20 @@ public :
|
||||
template <typename In, typename Out>
|
||||
static Out FromWide(In begin, In end, Out output);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert a latin-1 (ISO-5589-1) characters range to UTF-8
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
/// \param output Iterator pointing to the beginning of the output sequence
|
||||
/// \param locale Locale to use for conversion
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out FromLatin1(In begin, In end, Out output);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert an UTF-8 characters range to ANSI characters
|
||||
///
|
||||
@ -184,6 +198,20 @@ public :
|
||||
template <typename In, typename Out>
|
||||
static Out ToWide(In begin, In end, Out output, wchar_t replacement = 0);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert an UTF-8 characters range to latin-1 (ISO-5589-1) characters
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
/// \param output Iterator pointing to the beginning of the output sequence
|
||||
/// \param replacement Replacement for characters not convertible to wide (use 0 to skip them)
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out ToLatin1(In begin, In end, Out output, char replacement = 0);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert a UTF-8 characters range to UTF-8
|
||||
///
|
||||
@ -332,6 +360,20 @@ public :
|
||||
template <typename In, typename Out>
|
||||
static Out FromWide(In begin, In end, Out output);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert a latin-1 (ISO-5589-1) characters range to UTF-16
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
/// \param output Iterator pointing to the beginning of the output sequence
|
||||
/// \param locale Locale to use for conversion
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out FromLatin1(In begin, In end, Out output);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert an UTF-16 characters range to ANSI characters
|
||||
///
|
||||
@ -364,6 +406,20 @@ public :
|
||||
template <typename In, typename Out>
|
||||
static Out ToWide(In begin, In end, Out output, wchar_t replacement = 0);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert an UTF-16 characters range to latin-1 (ISO-5589-1) characters
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
/// \param output Iterator pointing to the beginning of the output sequence
|
||||
/// \param replacement Replacement for characters not convertible to wide (use 0 to skip them)
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out ToLatin1(In begin, In end, Out output, char replacement = 0);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert a UTF-16 characters range to UTF-8
|
||||
///
|
||||
@ -513,6 +569,20 @@ public :
|
||||
template <typename In, typename Out>
|
||||
static Out FromWide(In begin, In end, Out output);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert a latin-1 (ISO-5589-1) characters range to UTF-32
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
/// \param output Iterator pointing to the beginning of the output sequence
|
||||
/// \param locale Locale to use for conversion
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out FromLatin1(In begin, In end, Out output);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert an UTF-32 characters range to ANSI characters
|
||||
///
|
||||
@ -545,6 +615,20 @@ public :
|
||||
template <typename In, typename Out>
|
||||
static Out ToWide(In begin, In end, Out output, wchar_t replacement = 0);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert an UTF-16 characters range to latin-1 (ISO-5589-1) characters
|
||||
///
|
||||
/// \param begin Iterator pointing to the beginning of the input sequence
|
||||
/// \param end Iterator pointing to the end of the input sequence
|
||||
/// \param output Iterator pointing to the beginning of the output sequence
|
||||
/// \param replacement Replacement for characters not convertible to wide (use 0 to skip them)
|
||||
///
|
||||
/// \return Iterator to the end of the output sequence which has been written
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
static Out ToLatin1(In begin, In end, Out output, char replacement = 0);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Convert a UTF-32 characters range to UTF-8
|
||||
///
|
||||
|
@ -176,6 +176,19 @@ Out Utf<8>::FromWide(In begin, In end, Out output)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
Out Utf<8>::FromLatin1(In begin, In end, Out output)
|
||||
{
|
||||
// Latin-1 is directly compatible with Unicode encodings,
|
||||
// and can thus be treated as (a sub-range of) UTF-32
|
||||
while (begin < end)
|
||||
output = Encode(*begin++, output);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
Out Utf<8>::ToAnsi(In begin, In end, Out output, char replacement, const std::locale& locale)
|
||||
@ -206,6 +219,23 @@ Out Utf<8>::ToWide(In begin, In end, Out output, wchar_t replacement)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
Out Utf<8>::ToLatin1(In begin, In end, Out output, char replacement)
|
||||
{
|
||||
// Latin-1 is directly compatible with Unicode encodings,
|
||||
// and can thus be treated as (a sub-range of) UTF-32
|
||||
while (begin < end)
|
||||
{
|
||||
Uint32 codepoint;
|
||||
begin = Decode(begin, end, codepoint);
|
||||
*output++ = codepoint < 256 ? static_cast<char>(codepoint) : replacement;
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
Out Utf<8>::ToUtf8(In begin, In end, Out output)
|
||||
@ -376,6 +406,19 @@ Out Utf<16>::FromWide(In begin, In end, Out output)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
Out Utf<16>::FromLatin1(In begin, In end, Out output)
|
||||
{
|
||||
// Latin-1 is directly compatible with Unicode encodings,
|
||||
// and can thus be treated as (a sub-range of) UTF-32
|
||||
while (begin < end)
|
||||
*output++ = *begin++;
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
Out Utf<16>::ToAnsi(In begin, In end, Out output, char replacement, const std::locale& locale)
|
||||
@ -406,6 +449,22 @@ Out Utf<16>::ToWide(In begin, In end, Out output, wchar_t replacement)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
Out Utf<16>::ToLatin1(In begin, In end, Out output, char replacement)
|
||||
{
|
||||
// Latin-1 is directly compatible with Unicode encodings,
|
||||
// and can thus be treated as (a sub-range of) UTF-32
|
||||
while (begin < end)
|
||||
{
|
||||
*output++ = *begin < 256 ? static_cast<char>(*begin) : replacement;
|
||||
begin++;
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
Out Utf<16>::ToUtf8(In begin, In end, Out output)
|
||||
@ -503,6 +562,19 @@ Out Utf<32>::FromWide(In begin, In end, Out output)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
Out Utf<32>::FromLatin1(In begin, In end, Out output)
|
||||
{
|
||||
// Latin-1 is directly compatible with Unicode encodings,
|
||||
// and can thus be treated as (a sub-range of) UTF-32
|
||||
while (begin < end)
|
||||
*output++ = *begin++;
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
Out Utf<32>::ToAnsi(In begin, In end, Out output, char replacement, const std::locale& locale)
|
||||
@ -525,6 +597,22 @@ Out Utf<32>::ToWide(In begin, In end, Out output, wchar_t replacement)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
Out Utf<32>::ToLatin1(In begin, In end, Out output, char replacement)
|
||||
{
|
||||
// Latin-1 is directly compatible with Unicode encodings,
|
||||
// and can thus be treated as (a sub-range of) UTF-32
|
||||
while (begin < end)
|
||||
{
|
||||
*output++ = *begin < 256 ? static_cast<char>(*begin) : replacement;
|
||||
begin++;
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename In, typename Out>
|
||||
Out Utf<32>::ToUtf8(In begin, In end, Out output)
|
||||
|
Loading…
Reference in New Issue
Block a user