Punycode encoder/decoder: separate core and parts that depend on UTF8

encoder/decoder


Swift SVN r20307
This commit is contained in:
Dmitri Hrybenko
2014-07-22 14:37:37 +00:00
parent 87ed6c8a5b
commit 56342b0cfa
7 changed files with 117 additions and 81 deletions

View File

@@ -27,17 +27,27 @@
#include "swift/Basic/LLVM.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/SmallVector.h"
#include <vector>
#include <cstdint>
namespace swift {
namespace Punycode {
/// Encodes a UTF-8-encoded Unicode string into Punycode.
void encodePunycode(StringRef InputUTF8, std::string &OutPunycode);
/// Decodes a Punycode string into a UTF-8-encoded Unicode string.
/// Encodes a sequence of code points into Punycode.
///
/// Returns true if the encoding failed, false if it succeeded.
bool decodePunycode(StringRef InputPunycode, std::string &OutUTF8);
/// Returns false if input contains surrogate code points.
bool encodePunycode(const std::vector<uint32_t> &InputCodePoints,
std::string &OutPunycode);
/// Decodes a Punycode string into a sequence of Unicode scalars.
///
/// Returns false if decoding failed.
bool decodePunycode(StringRef InputPunycode,
std::vector<uint32_t> &OutCodePoints);
bool encodePunycodeUTF8(StringRef InputUTF8, std::string &OutPunycode);
bool decodePunycodeUTF8(StringRef InputPunycode, std::string &OutUTF8);
} // end namespace Punycode
} // end namespace swift