kidna.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "kidna.h"
00023
00024 #include <kdebug.h>
00025
00026 #include <idna.h>
00027 #include <stdlib.h>
00028
00029 #define IDNA_SUCCESS 0
00030
00031 QCString KIDNA::toAsciiCString(const QString &idna)
00032 {
00033 int l = idna.length();
00034 const QChar *u = idna.unicode();
00035 bool needConversion = false;
00036 for(;l--;)
00037 {
00038 if ((*u++).unicode() > 127)
00039 {
00040 needConversion = true;
00041 break;
00042 }
00043 }
00044 if (!needConversion)
00045 return idna.lower().latin1();
00046
00047
00048
00049 bool bStartsWithDot = (idna[0] == '.');
00050 char *pOutput;
00051 if (idna_to_ascii_8z(idna.utf8().data()+(bStartsWithDot ? 1: 0), &pOutput, 0) == IDNA_SUCCESS)
00052 {
00053 QCString result = pOutput;
00054 free(pOutput);
00055 if (bStartsWithDot)
00056 return "."+result;
00057 return result;
00058 }
00059 else
00060 {
00061 return 0;
00062 }
00063 }
00064
00065 QString KIDNA::toAscii(const QString &idna)
00066 {
00067 int l = idna.length();
00068 const QChar *u = idna.unicode();
00069 bool needConversion = false;
00070 for(;l--;)
00071 {
00072 if ((*u++).unicode() > 127)
00073 {
00074 needConversion = true;
00075 break;
00076 }
00077 }
00078 if (!needConversion)
00079 return idna.lower();
00080
00081
00082
00083 bool bStartsWithDot = (idna[0] == '.');
00084 char *pOutput;
00085 if (idna_to_ascii_8z(idna.utf8().data()+(bStartsWithDot ? 1: 0), &pOutput, 0) == IDNA_SUCCESS)
00086 {
00087 QString result(pOutput);
00088 free(pOutput);
00089 if (bStartsWithDot)
00090 return "."+result;
00091 return result;
00092 }
00093 else
00094 {
00095 return QString::null;
00096 }
00097 }
00098
00099 QString KIDNA::toUnicode(const QString &idna)
00100 {
00101 char *pOutput;
00102 if (idna_to_unicode_8z8z(idna.utf8(), &pOutput, 0) == IDNA_SUCCESS)
00103 {
00104 QString result = QString::fromUtf8(pOutput);
00105 free(pOutput);
00106 return result;
00107 }
00108 else
00109 {
00110 return idna.lower();
00111 }
00112 }
This file is part of the documentation for kdecore Library Version 3.2.3.