ICU 76.1  76.1
idna.h
Go to the documentation of this file.
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4 *******************************************************************************
5 * Copyright (C) 2010-2012, International Business Machines
6 * Corporation and others. All Rights Reserved.
7 *******************************************************************************
8 * file name: idna.h
9 * encoding: UTF-8
10 * tab size: 8 (not used)
11 * indentation:4
12 *
13 * created on: 2010mar05
14 * created by: Markus W. Scherer
15 */
16 
17 #ifndef __IDNA_H__
18 #define __IDNA_H__
19 
25 #include "unicode/utypes.h"
26 
27 #if U_SHOW_CPLUSPLUS_API
28 
29 #if !UCONFIG_NO_IDNA
30 
31 #include "unicode/bytestream.h"
32 #include "unicode/stringpiece.h"
33 #include "unicode/uidna.h"
34 #include "unicode/unistr.h"
35 
36 U_NAMESPACE_BEGIN
37 
38 class IDNAInfo;
39 
52 class U_COMMON_API IDNA : public UObject {
53 public:
58  ~IDNA();
59 
96  static IDNA *
97  createUTS46Instance(uint32_t options, UErrorCode &errorCode);
98 
119  virtual UnicodeString &
120  labelToASCII(const UnicodeString &label, UnicodeString &dest,
121  IDNAInfo &info, UErrorCode &errorCode) const = 0;
122 
141  virtual UnicodeString &
142  labelToUnicode(const UnicodeString &label, UnicodeString &dest,
143  IDNAInfo &info, UErrorCode &errorCode) const = 0;
144 
165  virtual UnicodeString &
166  nameToASCII(const UnicodeString &name, UnicodeString &dest,
167  IDNAInfo &info, UErrorCode &errorCode) const = 0;
168 
187  virtual UnicodeString &
188  nameToUnicode(const UnicodeString &name, UnicodeString &dest,
189  IDNAInfo &info, UErrorCode &errorCode) const = 0;
190 
191  // UTF-8 versions of the processing methods ---------------------------- ***
192 
207  virtual void
208  labelToASCII_UTF8(StringPiece label, ByteSink &dest,
209  IDNAInfo &info, UErrorCode &errorCode) const;
210 
225  virtual void
226  labelToUnicodeUTF8(StringPiece label, ByteSink &dest,
227  IDNAInfo &info, UErrorCode &errorCode) const;
228 
243  virtual void
244  nameToASCII_UTF8(StringPiece name, ByteSink &dest,
245  IDNAInfo &info, UErrorCode &errorCode) const;
246 
261  virtual void
262  nameToUnicodeUTF8(StringPiece name, ByteSink &dest,
263  IDNAInfo &info, UErrorCode &errorCode) const;
264 };
265 
266 class UTS46;
267 
273 class U_COMMON_API IDNAInfo : public UMemory {
274 public:
279  IDNAInfo() : errors(0), labelErrors(0), isTransDiff(false), isBiDi(false), isOkBiDi(true) {}
285  UBool hasErrors() const { return errors!=0; }
292  uint32_t getErrors() const { return errors; }
306  UBool isTransitionalDifferent() const { return isTransDiff; }
307 
308 private:
309  friend class UTS46;
310 
311  IDNAInfo(const IDNAInfo &other) = delete; // no copying
312  IDNAInfo &operator=(const IDNAInfo &other) = delete; // no copying
313 
314  void reset() {
315  errors=labelErrors=0;
316  isTransDiff=false;
317  isBiDi=false;
318  isOkBiDi=true;
319  }
320 
321  uint32_t errors, labelErrors;
322  UBool isTransDiff;
323  UBool isBiDi;
324  UBool isOkBiDi;
325 };
326 
327 U_NAMESPACE_END
328 
329 #endif // UCONFIG_NO_IDNA
330 
331 #endif /* U_SHOW_CPLUSPLUS_API */
332 
333 #endif // __IDNA_H__
Output container for IDNA processing errors.
Definition: idna.h:273
uint32_t getErrors() const
Returns a bit set indicating IDNA processing errors.
Definition: idna.h:292
UBool isTransitionalDifferent() const
Returns true if transitional and nontransitional processing produce different results.
Definition: idna.h:306
IDNAInfo()
Constructor for stack allocation.
Definition: idna.h:279
C++ API: Unicode String.
A ByteSink can be filled with bytes.
Definition: bytestream.h:53
C++ API: StringPiece: Read-only byte string wrapper class.
C++ API: Interface for writing bytes, and implementation classes.
C API: Internationalizing Domain Names in Applications (IDNA)
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:430
Basic definitions for ICU, for both C and C++ APIs.
#define U_COMMON_API
Set to export library symbols from inside the common library, and to import them from outside...
Definition: utypes.h:315
UBool hasErrors() const
Were there IDNA processing errors?
Definition: idna.h:285
UnicodeString is a string class that stores Unicode characters directly and provides similar function...
Definition: unistr.h:295
Abstract base class for IDNA processing.
Definition: idna.h:52
A string-like object that points to a sized piece of memory.
Definition: stringpiece.h:61
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:223
UMemory is the common ICU base class.
Definition: uobject.h:115
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition: umachine.h:247