|
|
|||
File indexing completed on 2026-06-02 08:58:14
0001 //////////////////////////////////////////////////////////// 0002 // 0003 // SFML - Simple and Fast Multimedia Library 0004 // Copyright (C) 2007-2023 Laurent Gomila (laurent@sfml-dev.org) 0005 // 0006 // This software is provided 'as-is', without any express or implied warranty. 0007 // In no event will the authors be held liable for any damages arising from the use of this software. 0008 // 0009 // Permission is granted to anyone to use this software for any purpose, 0010 // including commercial applications, and to alter it and redistribute it freely, 0011 // subject to the following restrictions: 0012 // 0013 // 1. The origin of this software must not be misrepresented; 0014 // you must not claim that you wrote the original software. 0015 // If you use this software in a product, an acknowledgment 0016 // in the product documentation would be appreciated but is not required. 0017 // 0018 // 2. Altered source versions must be plainly marked as such, 0019 // and must not be misrepresented as being the original software. 0020 // 0021 // 3. This notice may not be removed or altered from any source distribution. 0022 // 0023 //////////////////////////////////////////////////////////// 0024 0025 #ifndef SFML_UTF_HPP 0026 #define SFML_UTF_HPP 0027 0028 //////////////////////////////////////////////////////////// 0029 // Headers 0030 //////////////////////////////////////////////////////////// 0031 #include <SFML/Config.hpp> 0032 #include <algorithm> 0033 #include <locale> 0034 #include <string> 0035 #include <cstdlib> 0036 0037 0038 namespace sf 0039 { 0040 template <unsigned int N> 0041 class Utf; 0042 0043 //////////////////////////////////////////////////////////// 0044 /// \brief Specialization of the Utf template for UTF-8 0045 /// 0046 //////////////////////////////////////////////////////////// 0047 template <> 0048 class Utf<8> 0049 { 0050 public: 0051 0052 //////////////////////////////////////////////////////////// 0053 /// \brief Decode a single UTF-8 character 0054 /// 0055 /// Decoding a character means finding its unique 32-bits 0056 /// code (called the codepoint) in the Unicode standard. 0057 /// 0058 /// \param begin Iterator pointing to the beginning of the input sequence 0059 /// \param end Iterator pointing to the end of the input sequence 0060 /// \param output Codepoint of the decoded UTF-8 character 0061 /// \param replacement Replacement character to use in case the UTF-8 sequence is invalid 0062 /// 0063 /// \return Iterator pointing to one past the last read element of the input sequence 0064 /// 0065 //////////////////////////////////////////////////////////// 0066 template <typename In> 0067 static In decode(In begin, In end, Uint32& output, Uint32 replacement = 0); 0068 0069 //////////////////////////////////////////////////////////// 0070 /// \brief Encode a single UTF-8 character 0071 /// 0072 /// Encoding a character means converting a unique 32-bits 0073 /// code (called the codepoint) in the target encoding, UTF-8. 0074 /// 0075 /// \param input Codepoint to encode as UTF-8 0076 /// \param output Iterator pointing to the beginning of the output sequence 0077 /// \param replacement Replacement for characters not convertible to UTF-8 (use 0 to skip them) 0078 /// 0079 /// \return Iterator to the end of the output sequence which has been written 0080 /// 0081 //////////////////////////////////////////////////////////// 0082 template <typename Out> 0083 static Out encode(Uint32 input, Out output, Uint8 replacement = 0); 0084 0085 //////////////////////////////////////////////////////////// 0086 /// \brief Advance to the next UTF-8 character 0087 /// 0088 /// This function is necessary for multi-elements encodings, as 0089 /// a single character may use more than 1 storage element. 0090 /// 0091 /// \param begin Iterator pointing to the beginning of the input sequence 0092 /// \param end Iterator pointing to the end of the input sequence 0093 /// 0094 /// \return Iterator pointing to one past the last read element of the input sequence 0095 /// 0096 //////////////////////////////////////////////////////////// 0097 template <typename In> 0098 static In next(In begin, In end); 0099 0100 //////////////////////////////////////////////////////////// 0101 /// \brief Count the number of characters of a UTF-8 sequence 0102 /// 0103 /// This function is necessary for multi-elements encodings, as 0104 /// a single character may use more than 1 storage element, thus the 0105 /// total size can be different from (begin - end). 0106 /// 0107 /// \param begin Iterator pointing to the beginning of the input sequence 0108 /// \param end Iterator pointing to the end of the input sequence 0109 /// 0110 /// \return Iterator pointing to one past the last read element of the input sequence 0111 /// 0112 //////////////////////////////////////////////////////////// 0113 template <typename In> 0114 static std::size_t count(In begin, In end); 0115 0116 //////////////////////////////////////////////////////////// 0117 /// \brief Convert an ANSI characters range to UTF-8 0118 /// 0119 /// The current global locale will be used by default, unless you 0120 /// pass a custom one in the \a locale parameter. 0121 /// 0122 /// \param begin Iterator pointing to the beginning of the input sequence 0123 /// \param end Iterator pointing to the end of the input sequence 0124 /// \param output Iterator pointing to the beginning of the output sequence 0125 /// \param locale Locale to use for conversion 0126 /// 0127 /// \return Iterator to the end of the output sequence which has been written 0128 /// 0129 //////////////////////////////////////////////////////////// 0130 template <typename In, typename Out> 0131 static Out fromAnsi(In begin, In end, Out output, const std::locale& locale = std::locale()); 0132 0133 //////////////////////////////////////////////////////////// 0134 /// \brief Convert a wide characters range to UTF-8 0135 /// 0136 /// \param begin Iterator pointing to the beginning of the input sequence 0137 /// \param end Iterator pointing to the end of the input sequence 0138 /// \param output Iterator pointing to the beginning of the output sequence 0139 /// 0140 /// \return Iterator to the end of the output sequence which has been written 0141 /// 0142 //////////////////////////////////////////////////////////// 0143 template <typename In, typename Out> 0144 static Out fromWide(In begin, In end, Out output); 0145 0146 //////////////////////////////////////////////////////////// 0147 /// \brief Convert a latin-1 (ISO-5589-1) characters range to UTF-8 0148 /// 0149 /// \param begin Iterator pointing to the beginning of the input sequence 0150 /// \param end Iterator pointing to the end of the input sequence 0151 /// \param output Iterator pointing to the beginning of the output sequence 0152 /// 0153 /// \return Iterator to the end of the output sequence which has been written 0154 /// 0155 //////////////////////////////////////////////////////////// 0156 template <typename In, typename Out> 0157 static Out fromLatin1(In begin, In end, Out output); 0158 0159 //////////////////////////////////////////////////////////// 0160 /// \brief Convert an UTF-8 characters range to ANSI characters 0161 /// 0162 /// The current global locale will be used by default, unless you 0163 /// pass a custom one in the \a locale parameter. 0164 /// 0165 /// \param begin Iterator pointing to the beginning of the input sequence 0166 /// \param end Iterator pointing to the end of the input sequence 0167 /// \param output Iterator pointing to the beginning of the output sequence 0168 /// \param replacement Replacement for characters not convertible to ANSI (use 0 to skip them) 0169 /// \param locale Locale to use for conversion 0170 /// 0171 /// \return Iterator to the end of the output sequence which has been written 0172 /// 0173 //////////////////////////////////////////////////////////// 0174 template <typename In, typename Out> 0175 static Out toAnsi(In begin, In end, Out output, char replacement = 0, const std::locale& locale = std::locale()); 0176 0177 //////////////////////////////////////////////////////////// 0178 /// \brief Convert an UTF-8 characters range to wide characters 0179 /// 0180 /// \param begin Iterator pointing to the beginning of the input sequence 0181 /// \param end Iterator pointing to the end of the input sequence 0182 /// \param output Iterator pointing to the beginning of the output sequence 0183 /// \param replacement Replacement for characters not convertible to wide (use 0 to skip them) 0184 /// 0185 /// \return Iterator to the end of the output sequence which has been written 0186 /// 0187 //////////////////////////////////////////////////////////// 0188 template <typename In, typename Out> 0189 static Out toWide(In begin, In end, Out output, wchar_t replacement = 0); 0190 0191 //////////////////////////////////////////////////////////// 0192 /// \brief Convert an UTF-8 characters range to latin-1 (ISO-5589-1) characters 0193 /// 0194 /// \param begin Iterator pointing to the beginning of the input sequence 0195 /// \param end Iterator pointing to the end of the input sequence 0196 /// \param output Iterator pointing to the beginning of the output sequence 0197 /// \param replacement Replacement for characters not convertible to wide (use 0 to skip them) 0198 /// 0199 /// \return Iterator to the end of the output sequence which has been written 0200 /// 0201 //////////////////////////////////////////////////////////// 0202 template <typename In, typename Out> 0203 static Out toLatin1(In begin, In end, Out output, char replacement = 0); 0204 0205 //////////////////////////////////////////////////////////// 0206 /// \brief Convert a UTF-8 characters range to UTF-8 0207 /// 0208 /// This functions does nothing more than a direct copy; 0209 /// it is defined only to provide the same interface as other 0210 /// specializations of the sf::Utf<> template, and allow 0211 /// generic code to be written on top of it. 0212 /// 0213 /// \param begin Iterator pointing to the beginning of the input sequence 0214 /// \param end Iterator pointing to the end of the input sequence 0215 /// \param output Iterator pointing to the beginning of the output sequence 0216 /// 0217 /// \return Iterator to the end of the output sequence which has been written 0218 /// 0219 //////////////////////////////////////////////////////////// 0220 template <typename In, typename Out> 0221 static Out toUtf8(In begin, In end, Out output); 0222 0223 //////////////////////////////////////////////////////////// 0224 /// \brief Convert a UTF-8 characters range to UTF-16 0225 /// 0226 /// \param begin Iterator pointing to the beginning of the input sequence 0227 /// \param end Iterator pointing to the end of the input sequence 0228 /// \param output Iterator pointing to the beginning of the output sequence 0229 /// 0230 /// \return Iterator to the end of the output sequence which has been written 0231 /// 0232 //////////////////////////////////////////////////////////// 0233 template <typename In, typename Out> 0234 static Out toUtf16(In begin, In end, Out output); 0235 0236 //////////////////////////////////////////////////////////// 0237 /// \brief Convert a UTF-8 characters range to UTF-32 0238 /// 0239 /// \param begin Iterator pointing to the beginning of the input sequence 0240 /// \param end Iterator pointing to the end of the input sequence 0241 /// \param output Iterator pointing to the beginning of the output sequence 0242 /// 0243 /// \return Iterator to the end of the output sequence which has been written 0244 /// 0245 //////////////////////////////////////////////////////////// 0246 template <typename In, typename Out> 0247 static Out toUtf32(In begin, In end, Out output); 0248 }; 0249 0250 //////////////////////////////////////////////////////////// 0251 /// \brief Specialization of the Utf template for UTF-16 0252 /// 0253 //////////////////////////////////////////////////////////// 0254 template <> 0255 class Utf<16> 0256 { 0257 public: 0258 0259 //////////////////////////////////////////////////////////// 0260 /// \brief Decode a single UTF-16 character 0261 /// 0262 /// Decoding a character means finding its unique 32-bits 0263 /// code (called the codepoint) in the Unicode standard. 0264 /// 0265 /// \param begin Iterator pointing to the beginning of the input sequence 0266 /// \param end Iterator pointing to the end of the input sequence 0267 /// \param output Codepoint of the decoded UTF-16 character 0268 /// \param replacement Replacement character to use in case the UTF-8 sequence is invalid 0269 /// 0270 /// \return Iterator pointing to one past the last read element of the input sequence 0271 /// 0272 //////////////////////////////////////////////////////////// 0273 template <typename In> 0274 static In decode(In begin, In end, Uint32& output, Uint32 replacement = 0); 0275 0276 //////////////////////////////////////////////////////////// 0277 /// \brief Encode a single UTF-16 character 0278 /// 0279 /// Encoding a character means converting a unique 32-bits 0280 /// code (called the codepoint) in the target encoding, UTF-16. 0281 /// 0282 /// \param input Codepoint to encode as UTF-16 0283 /// \param output Iterator pointing to the beginning of the output sequence 0284 /// \param replacement Replacement for characters not convertible to UTF-16 (use 0 to skip them) 0285 /// 0286 /// \return Iterator to the end of the output sequence which has been written 0287 /// 0288 //////////////////////////////////////////////////////////// 0289 template <typename Out> 0290 static Out encode(Uint32 input, Out output, Uint16 replacement = 0); 0291 0292 //////////////////////////////////////////////////////////// 0293 /// \brief Advance to the next UTF-16 character 0294 /// 0295 /// This function is necessary for multi-elements encodings, as 0296 /// a single character may use more than 1 storage element. 0297 /// 0298 /// \param begin Iterator pointing to the beginning of the input sequence 0299 /// \param end Iterator pointing to the end of the input sequence 0300 /// 0301 /// \return Iterator pointing to one past the last read element of the input sequence 0302 /// 0303 //////////////////////////////////////////////////////////// 0304 template <typename In> 0305 static In next(In begin, In end); 0306 0307 //////////////////////////////////////////////////////////// 0308 /// \brief Count the number of characters of a UTF-16 sequence 0309 /// 0310 /// This function is necessary for multi-elements encodings, as 0311 /// a single character may use more than 1 storage element, thus the 0312 /// total size can be different from (begin - end). 0313 /// 0314 /// \param begin Iterator pointing to the beginning of the input sequence 0315 /// \param end Iterator pointing to the end of the input sequence 0316 /// 0317 /// \return Iterator pointing to one past the last read element of the input sequence 0318 /// 0319 //////////////////////////////////////////////////////////// 0320 template <typename In> 0321 static std::size_t count(In begin, In end); 0322 0323 //////////////////////////////////////////////////////////// 0324 /// \brief Convert an ANSI characters range to UTF-16 0325 /// 0326 /// The current global locale will be used by default, unless you 0327 /// pass a custom one in the \a locale parameter. 0328 /// 0329 /// \param begin Iterator pointing to the beginning of the input sequence 0330 /// \param end Iterator pointing to the end of the input sequence 0331 /// \param output Iterator pointing to the beginning of the output sequence 0332 /// \param locale Locale to use for conversion 0333 /// 0334 /// \return Iterator to the end of the output sequence which has been written 0335 /// 0336 //////////////////////////////////////////////////////////// 0337 template <typename In, typename Out> 0338 static Out fromAnsi(In begin, In end, Out output, const std::locale& locale = std::locale()); 0339 0340 //////////////////////////////////////////////////////////// 0341 /// \brief Convert a wide characters range to UTF-16 0342 /// 0343 /// \param begin Iterator pointing to the beginning of the input sequence 0344 /// \param end Iterator pointing to the end of the input sequence 0345 /// \param output Iterator pointing to the beginning of the output sequence 0346 /// 0347 /// \return Iterator to the end of the output sequence which has been written 0348 /// 0349 //////////////////////////////////////////////////////////// 0350 template <typename In, typename Out> 0351 static Out fromWide(In begin, In end, Out output); 0352 0353 //////////////////////////////////////////////////////////// 0354 /// \brief Convert a latin-1 (ISO-5589-1) characters range to UTF-16 0355 /// 0356 /// \param begin Iterator pointing to the beginning of the input sequence 0357 /// \param end Iterator pointing to the end of the input sequence 0358 /// \param output Iterator pointing to the beginning of the output sequence 0359 /// 0360 /// \return Iterator to the end of the output sequence which has been written 0361 /// 0362 //////////////////////////////////////////////////////////// 0363 template <typename In, typename Out> 0364 static Out fromLatin1(In begin, In end, Out output); 0365 0366 //////////////////////////////////////////////////////////// 0367 /// \brief Convert an UTF-16 characters range to ANSI characters 0368 /// 0369 /// The current global locale will be used by default, unless you 0370 /// pass a custom one in the \a locale parameter. 0371 /// 0372 /// \param begin Iterator pointing to the beginning of the input sequence 0373 /// \param end Iterator pointing to the end of the input sequence 0374 /// \param output Iterator pointing to the beginning of the output sequence 0375 /// \param replacement Replacement for characters not convertible to ANSI (use 0 to skip them) 0376 /// \param locale Locale to use for conversion 0377 /// 0378 /// \return Iterator to the end of the output sequence which has been written 0379 /// 0380 //////////////////////////////////////////////////////////// 0381 template <typename In, typename Out> 0382 static Out toAnsi(In begin, In end, Out output, char replacement = 0, const std::locale& locale = std::locale()); 0383 0384 //////////////////////////////////////////////////////////// 0385 /// \brief Convert an UTF-16 characters range to wide characters 0386 /// 0387 /// \param begin Iterator pointing to the beginning of the input sequence 0388 /// \param end Iterator pointing to the end of the input sequence 0389 /// \param output Iterator pointing to the beginning of the output sequence 0390 /// \param replacement Replacement for characters not convertible to wide (use 0 to skip them) 0391 /// 0392 /// \return Iterator to the end of the output sequence which has been written 0393 /// 0394 //////////////////////////////////////////////////////////// 0395 template <typename In, typename Out> 0396 static Out toWide(In begin, In end, Out output, wchar_t replacement = 0); 0397 0398 //////////////////////////////////////////////////////////// 0399 /// \brief Convert an UTF-16 characters range to latin-1 (ISO-5589-1) characters 0400 /// 0401 /// \param begin Iterator pointing to the beginning of the input sequence 0402 /// \param end Iterator pointing to the end of the input sequence 0403 /// \param output Iterator pointing to the beginning of the output sequence 0404 /// \param replacement Replacement for characters not convertible to wide (use 0 to skip them) 0405 /// 0406 /// \return Iterator to the end of the output sequence which has been written 0407 /// 0408 //////////////////////////////////////////////////////////// 0409 template <typename In, typename Out> 0410 static Out toLatin1(In begin, In end, Out output, char replacement = 0); 0411 0412 //////////////////////////////////////////////////////////// 0413 /// \brief Convert a UTF-16 characters range to UTF-8 0414 /// 0415 /// \param begin Iterator pointing to the beginning of the input sequence 0416 /// \param end Iterator pointing to the end of the input sequence 0417 /// \param output Iterator pointing to the beginning of the output sequence 0418 /// 0419 /// \return Iterator to the end of the output sequence which has been written 0420 /// 0421 //////////////////////////////////////////////////////////// 0422 template <typename In, typename Out> 0423 static Out toUtf8(In begin, In end, Out output); 0424 0425 //////////////////////////////////////////////////////////// 0426 /// \brief Convert a UTF-16 characters range to UTF-16 0427 /// 0428 /// This functions does nothing more than a direct copy; 0429 /// it is defined only to provide the same interface as other 0430 /// specializations of the sf::Utf<> template, and allow 0431 /// generic code to be written on top of it. 0432 /// 0433 /// \param begin Iterator pointing to the beginning of the input sequence 0434 /// \param end Iterator pointing to the end of the input sequence 0435 /// \param output Iterator pointing to the beginning of the output sequence 0436 /// 0437 /// \return Iterator to the end of the output sequence which has been written 0438 /// 0439 //////////////////////////////////////////////////////////// 0440 template <typename In, typename Out> 0441 static Out toUtf16(In begin, In end, Out output); 0442 0443 //////////////////////////////////////////////////////////// 0444 /// \brief Convert a UTF-16 characters range to UTF-32 0445 /// 0446 /// \param begin Iterator pointing to the beginning of the input sequence 0447 /// \param end Iterator pointing to the end of the input sequence 0448 /// \param output Iterator pointing to the beginning of the output sequence 0449 /// 0450 /// \return Iterator to the end of the output sequence which has been written 0451 /// 0452 //////////////////////////////////////////////////////////// 0453 template <typename In, typename Out> 0454 static Out toUtf32(In begin, In end, Out output); 0455 }; 0456 0457 //////////////////////////////////////////////////////////// 0458 /// \brief Specialization of the Utf template for UTF-32 0459 /// 0460 //////////////////////////////////////////////////////////// 0461 template <> 0462 class Utf<32> 0463 { 0464 public: 0465 0466 //////////////////////////////////////////////////////////// 0467 /// \brief Decode a single UTF-32 character 0468 /// 0469 /// Decoding a character means finding its unique 32-bits 0470 /// code (called the codepoint) in the Unicode standard. 0471 /// For UTF-32, the character value is the same as the codepoint. 0472 /// 0473 /// \param begin Iterator pointing to the beginning of the input sequence 0474 /// \param end Iterator pointing to the end of the input sequence 0475 /// \param output Codepoint of the decoded UTF-32 character 0476 /// \param replacement Replacement character to use in case the UTF-8 sequence is invalid 0477 /// 0478 /// \return Iterator pointing to one past the last read element of the input sequence 0479 /// 0480 //////////////////////////////////////////////////////////// 0481 template <typename In> 0482 static In decode(In begin, In end, Uint32& output, Uint32 replacement = 0); 0483 0484 //////////////////////////////////////////////////////////// 0485 /// \brief Encode a single UTF-32 character 0486 /// 0487 /// Encoding a character means converting a unique 32-bits 0488 /// code (called the codepoint) in the target encoding, UTF-32. 0489 /// For UTF-32, the codepoint is the same as the character value. 0490 /// 0491 /// \param input Codepoint to encode as UTF-32 0492 /// \param output Iterator pointing to the beginning of the output sequence 0493 /// \param replacement Replacement for characters not convertible to UTF-32 (use 0 to skip them) 0494 /// 0495 /// \return Iterator to the end of the output sequence which has been written 0496 /// 0497 //////////////////////////////////////////////////////////// 0498 template <typename Out> 0499 static Out encode(Uint32 input, Out output, Uint32 replacement = 0); 0500 0501 //////////////////////////////////////////////////////////// 0502 /// \brief Advance to the next UTF-32 character 0503 /// 0504 /// This function is trivial for UTF-32, which can store 0505 /// every character in a single storage element. 0506 /// 0507 /// \param begin Iterator pointing to the beginning of the input sequence 0508 /// \param end Iterator pointing to the end of the input sequence 0509 /// 0510 /// \return Iterator pointing to one past the last read element of the input sequence 0511 /// 0512 //////////////////////////////////////////////////////////// 0513 template <typename In> 0514 static In next(In begin, In end); 0515 0516 //////////////////////////////////////////////////////////// 0517 /// \brief Count the number of characters of a UTF-32 sequence 0518 /// 0519 /// This function is trivial for UTF-32, which can store 0520 /// every character in a single storage element. 0521 /// 0522 /// \param begin Iterator pointing to the beginning of the input sequence 0523 /// \param end Iterator pointing to the end of the input sequence 0524 /// 0525 /// \return Iterator pointing to one past the last read element of the input sequence 0526 /// 0527 //////////////////////////////////////////////////////////// 0528 template <typename In> 0529 static std::size_t count(In begin, In end); 0530 0531 //////////////////////////////////////////////////////////// 0532 /// \brief Convert an ANSI characters range to UTF-32 0533 /// 0534 /// The current global locale will be used by default, unless you 0535 /// pass a custom one in the \a locale parameter. 0536 /// 0537 /// \param begin Iterator pointing to the beginning of the input sequence 0538 /// \param end Iterator pointing to the end of the input sequence 0539 /// \param output Iterator pointing to the beginning of the output sequence 0540 /// \param locale Locale to use for conversion 0541 /// 0542 /// \return Iterator to the end of the output sequence which has been written 0543 /// 0544 //////////////////////////////////////////////////////////// 0545 template <typename In, typename Out> 0546 static Out fromAnsi(In begin, In end, Out output, const std::locale& locale = std::locale()); 0547 0548 //////////////////////////////////////////////////////////// 0549 /// \brief Convert a wide characters range to UTF-32 0550 /// 0551 /// \param begin Iterator pointing to the beginning of the input sequence 0552 /// \param end Iterator pointing to the end of the input sequence 0553 /// \param output Iterator pointing to the beginning of the output sequence 0554 /// 0555 /// \return Iterator to the end of the output sequence which has been written 0556 /// 0557 //////////////////////////////////////////////////////////// 0558 template <typename In, typename Out> 0559 static Out fromWide(In begin, In end, Out output); 0560 0561 //////////////////////////////////////////////////////////// 0562 /// \brief Convert a latin-1 (ISO-5589-1) characters range to UTF-32 0563 /// 0564 /// \param begin Iterator pointing to the beginning of the input sequence 0565 /// \param end Iterator pointing to the end of the input sequence 0566 /// \param output Iterator pointing to the beginning of the output sequence 0567 /// 0568 /// \return Iterator to the end of the output sequence which has been written 0569 /// 0570 //////////////////////////////////////////////////////////// 0571 template <typename In, typename Out> 0572 static Out fromLatin1(In begin, In end, Out output); 0573 0574 //////////////////////////////////////////////////////////// 0575 /// \brief Convert an UTF-32 characters range to ANSI characters 0576 /// 0577 /// The current global locale will be used by default, unless you 0578 /// pass a custom one in the \a locale parameter. 0579 /// 0580 /// \param begin Iterator pointing to the beginning of the input sequence 0581 /// \param end Iterator pointing to the end of the input sequence 0582 /// \param output Iterator pointing to the beginning of the output sequence 0583 /// \param replacement Replacement for characters not convertible to ANSI (use 0 to skip them) 0584 /// \param locale Locale to use for conversion 0585 /// 0586 /// \return Iterator to the end of the output sequence which has been written 0587 /// 0588 //////////////////////////////////////////////////////////// 0589 template <typename In, typename Out> 0590 static Out toAnsi(In begin, In end, Out output, char replacement = 0, const std::locale& locale = std::locale()); 0591 0592 //////////////////////////////////////////////////////////// 0593 /// \brief Convert an UTF-32 characters range to wide characters 0594 /// 0595 /// \param begin Iterator pointing to the beginning of the input sequence 0596 /// \param end Iterator pointing to the end of the input sequence 0597 /// \param output Iterator pointing to the beginning of the output sequence 0598 /// \param replacement Replacement for characters not convertible to wide (use 0 to skip them) 0599 /// 0600 /// \return Iterator to the end of the output sequence which has been written 0601 /// 0602 //////////////////////////////////////////////////////////// 0603 template <typename In, typename Out> 0604 static Out toWide(In begin, In end, Out output, wchar_t replacement = 0); 0605 0606 //////////////////////////////////////////////////////////// 0607 /// \brief Convert an UTF-16 characters range to latin-1 (ISO-5589-1) characters 0608 /// 0609 /// \param begin Iterator pointing to the beginning of the input sequence 0610 /// \param end Iterator pointing to the end of the input sequence 0611 /// \param output Iterator pointing to the beginning of the output sequence 0612 /// \param replacement Replacement for characters not convertible to wide (use 0 to skip them) 0613 /// 0614 /// \return Iterator to the end of the output sequence which has been written 0615 /// 0616 //////////////////////////////////////////////////////////// 0617 template <typename In, typename Out> 0618 static Out toLatin1(In begin, In end, Out output, char replacement = 0); 0619 0620 //////////////////////////////////////////////////////////// 0621 /// \brief Convert a UTF-32 characters range to UTF-8 0622 /// 0623 /// \param begin Iterator pointing to the beginning of the input sequence 0624 /// \param end Iterator pointing to the end of the input sequence 0625 /// \param output Iterator pointing to the beginning of the output sequence 0626 /// 0627 /// \return Iterator to the end of the output sequence which has been written 0628 /// 0629 //////////////////////////////////////////////////////////// 0630 template <typename In, typename Out> 0631 static Out toUtf8(In begin, In end, Out output); 0632 0633 //////////////////////////////////////////////////////////// 0634 /// \brief Convert a UTF-32 characters range to UTF-16 0635 /// 0636 /// \param begin Iterator pointing to the beginning of the input sequence 0637 /// \param end Iterator pointing to the end of the input sequence 0638 /// \param output Iterator pointing to the beginning of the output sequence 0639 /// 0640 /// \return Iterator to the end of the output sequence which has been written 0641 /// 0642 //////////////////////////////////////////////////////////// 0643 template <typename In, typename Out> 0644 static Out toUtf16(In begin, In end, Out output); 0645 0646 //////////////////////////////////////////////////////////// 0647 /// \brief Convert a UTF-32 characters range to UTF-32 0648 /// 0649 /// This functions does nothing more than a direct copy; 0650 /// it is defined only to provide the same interface as other 0651 /// specializations of the sf::Utf<> template, and allow 0652 /// generic code to be written on top of it. 0653 /// 0654 /// \param begin Iterator pointing to the beginning of the input sequence 0655 /// \param end Iterator pointing to the end of the input sequence 0656 /// \param output Iterator pointing to the beginning of the output sequence 0657 /// 0658 /// \return Iterator to the end of the output sequence which has been written 0659 /// 0660 //////////////////////////////////////////////////////////// 0661 template <typename In, typename Out> 0662 static Out toUtf32(In begin, In end, Out output); 0663 0664 //////////////////////////////////////////////////////////// 0665 /// \brief Decode a single ANSI character to UTF-32 0666 /// 0667 /// This function does not exist in other specializations 0668 /// of sf::Utf<>, it is defined for convenience (it is used by 0669 /// several other conversion functions). 0670 /// 0671 /// \param input Input ANSI character 0672 /// \param locale Locale to use for conversion 0673 /// 0674 /// \return Converted character 0675 /// 0676 //////////////////////////////////////////////////////////// 0677 template <typename In> 0678 static Uint32 decodeAnsi(In input, const std::locale& locale = std::locale()); 0679 0680 //////////////////////////////////////////////////////////// 0681 /// \brief Decode a single wide character to UTF-32 0682 /// 0683 /// This function does not exist in other specializations 0684 /// of sf::Utf<>, it is defined for convenience (it is used by 0685 /// several other conversion functions). 0686 /// 0687 /// \param input Input wide character 0688 /// 0689 /// \return Converted character 0690 /// 0691 //////////////////////////////////////////////////////////// 0692 template <typename In> 0693 static Uint32 decodeWide(In input); 0694 0695 //////////////////////////////////////////////////////////// 0696 /// \brief Encode a single UTF-32 character to ANSI 0697 /// 0698 /// This function does not exist in other specializations 0699 /// of sf::Utf<>, it is defined for convenience (it is used by 0700 /// several other conversion functions). 0701 /// 0702 /// \param codepoint Iterator pointing to the beginning of the input sequence 0703 /// \param output Iterator pointing to the beginning of the output sequence 0704 /// \param replacement Replacement if the input character is not convertible to ANSI (use 0 to skip it) 0705 /// \param locale Locale to use for conversion 0706 /// 0707 /// \return Iterator to the end of the output sequence which has been written 0708 /// 0709 //////////////////////////////////////////////////////////// 0710 template <typename Out> 0711 static Out encodeAnsi(Uint32 codepoint, Out output, char replacement = 0, const std::locale& locale = std::locale()); 0712 0713 //////////////////////////////////////////////////////////// 0714 /// \brief Encode a single UTF-32 character to wide 0715 /// 0716 /// This function does not exist in other specializations 0717 /// of sf::Utf<>, it is defined for convenience (it is used by 0718 /// several other conversion functions). 0719 /// 0720 /// \param codepoint Iterator pointing to the beginning of the input sequence 0721 /// \param output Iterator pointing to the beginning of the output sequence 0722 /// \param replacement Replacement if the input character is not convertible to wide (use 0 to skip it) 0723 /// 0724 /// \return Iterator to the end of the output sequence which has been written 0725 /// 0726 //////////////////////////////////////////////////////////// 0727 template <typename Out> 0728 static Out encodeWide(Uint32 codepoint, Out output, wchar_t replacement = 0); 0729 }; 0730 0731 #include <SFML/System/Utf.inl> 0732 0733 // Make typedefs to get rid of the template syntax 0734 typedef Utf<8> Utf8; 0735 typedef Utf<16> Utf16; 0736 typedef Utf<32> Utf32; 0737 0738 } // namespace sf 0739 0740 0741 #endif // SFML_UTF_HPP 0742 0743 0744 //////////////////////////////////////////////////////////// 0745 /// \class sf::Utf 0746 /// \ingroup system 0747 /// 0748 /// Utility class providing generic functions for UTF conversions. 0749 /// 0750 /// sf::Utf is a low-level, generic interface for counting, iterating, 0751 /// encoding and decoding Unicode characters and strings. It is able 0752 /// to handle ANSI, wide, latin-1, UTF-8, UTF-16 and UTF-32 encodings. 0753 /// 0754 /// sf::Utf<X> functions are all static, these classes are not meant to 0755 /// be instantiated. All the functions are template, so that you 0756 /// can use any character / string type for a given encoding. 0757 /// 0758 /// It has 3 specializations: 0759 /// \li sf::Utf<8> (typedef'd to sf::Utf8) 0760 /// \li sf::Utf<16> (typedef'd to sf::Utf16) 0761 /// \li sf::Utf<32> (typedef'd to sf::Utf32) 0762 /// 0763 ////////////////////////////////////////////////////////////
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|