IccMAX 2.1.27
Color Profile Tools
Loading...
Searching...
No Matches
CIccLocalizedUnicode Class Reference

#include <IccTagBasic.h>

Public Member Functions

 CIccLocalizedUnicode ()
 
 CIccLocalizedUnicode (const CIccLocalizedUnicode &ILU)
 
virtual ~CIccLocalizedUnicode ()
 
icUInt16NumberGetBuf () const
 
icUInt32Number GetLength () const
 
bool GetText (std::string &text)
 
const icCharGetUtf8 (icChar *szBuf, icUInt32Number nBufSize)
 
icUInt32Number GetUtf8Size ()
 
CIccLocalizedUnicodeoperator= (const CIccLocalizedUnicode &UnicodeText)
 
const icCharoperator= (const icChar *szText)
 
const icUInt16Numberoperator= (const icUInt16Number *sszText)
 
const icUInt32Numberoperator= (const icUInt32Number *sszText)
 
bool SetSize (icUInt32Number)
 
bool SetText (const icChar *szText, icLanguageCode nLanguageCode=icLanguageCodeEnglish, icCountryCode nRegionCode=icCountryCodeUSA)
 
bool SetText (const icUInt16Number *sszUnicode16Text, icLanguageCode nLanguageCode=icLanguageCodeEnglish, icCountryCode nRegionCode=icCountryCodeUSA)
 
bool SetText (const icUInt32Number *sszUnicode32Text, icLanguageCode nLanguageCode=icLanguageCodeEnglish, icCountryCode nRegionCode=icCountryCodeUSA)
 

Data Fields

icCountryCode m_nCountryCode
 
icLanguageCode m_nLanguageCode
 

Protected Attributes

icUInt32Number m_nLength
 
icUInt16Numberm_pBuf
 

Detailed Description

Data Class: CIccLocalizedUnicode

Purpose: Implementation of a unicode string with language and region identifiers.

Constructor & Destructor Documentation

◆ CIccLocalizedUnicode() [1/2]

CIccLocalizedUnicode::CIccLocalizedUnicode ( )

Name: CIccLocalizedUnicode::CIccLocalizedUnicode

Purpose: Constructor

6955{
6956 m_pBuf = (icUInt16Number*)malloc(1*sizeof(icUInt16Number));
6957 *m_pBuf = 0;
6958 m_nLength = 0;
6959}
unsigned short icUInt16Number
Definition icProfileHeader.h:256
icUInt32Number m_nLength
Definition IccTagBasic.h:1205
icUInt16Number * m_pBuf
Definition IccTagBasic.h:1207

References m_nLength, and m_pBuf.

◆ CIccLocalizedUnicode() [2/2]

CIccLocalizedUnicode::CIccLocalizedUnicode ( const CIccLocalizedUnicode ILU)

Name: CIccLocalizedUnicode::CIccLocalizedUnicode

Purpose: Copy Constructor

Args: ILU = The CIccLocalizedUnicode object to be copied

6973{
6974 m_nLength = ILU.GetLength();
6975 m_pBuf = (icUInt16Number*)malloc((m_nLength+1) * sizeof(icUInt16Number));
6976 if (m_nLength)
6977 memcpy(m_pBuf, ILU.GetBuf(), m_nLength*sizeof(icUInt16Number));
6978 m_pBuf[m_nLength] = 0;
6981}
icLanguageCode m_nLanguageCode
Definition IccTagBasic.h:1201
icUInt16Number * GetBuf() const
Definition IccTagBasic.h:1177
icUInt32Number GetLength() const
Definition IccTagBasic.h:1176
icCountryCode m_nCountryCode
Definition IccTagBasic.h:1202

References GetBuf(), GetLength(), m_nCountryCode, m_nLanguageCode, m_nLength, and m_pBuf.

+ Here is the call graph for this function:

◆ ~CIccLocalizedUnicode()

CIccLocalizedUnicode::~CIccLocalizedUnicode ( )
virtual

Name: CIccLocalizedUnicode::~CIccLocalizedUnicode

Purpose: Destructor

7018{
7019 if (m_pBuf)
7020 free(m_pBuf);
7021}

References m_pBuf.

Member Function Documentation

◆ GetBuf()

icUInt16Number * CIccLocalizedUnicode::GetBuf ( ) const
inline
1177{ return m_pBuf; }

References m_pBuf.

Referenced by CIccLocalizedUnicode(), operator=(), CIccTagMultiLocalizedUnicode::Read(), CIccTagXmlMultiLocalizedUnicode::ToXml(), CIccTagXmlProfileSequenceId::ToXml(), CIccTagXmlDict::ToXml(), and CIccTagMultiLocalizedUnicode::Write().

+ Here is the caller graph for this function:

◆ GetLength()

icUInt32Number CIccLocalizedUnicode::GetLength ( ) const
inline
1176{ return m_nLength; }

References m_nLength.

Referenced by CIccLocalizedUnicode(), operator=(), CIccTagXmlMultiLocalizedUnicode::ToXml(), CIccTagXmlProfileSequenceId::ToXml(), CIccTagXmlDict::ToXml(), and CIccTagMultiLocalizedUnicode::Write().

+ Here is the caller graph for this function:

◆ GetText()

bool CIccLocalizedUnicode::GetText ( std::string &  sText)

Name: CIccLocalizedUnicode::GetText

Purpose: Gets text as a UTF-8 string

Args: sText - string to put results in

7084{
7085 sText.clear();
7086
7087 icUInt16Number* str = m_pBuf;
7088 while (*str) {
7089 icUInt32Number code32 = 0x0;
7090
7091 //UTF-16 to UTF-32
7092
7093 if (*str <= 0xD7FF) {
7094 code32 = *str;
7095 str++;
7096 }
7097 else if (*str <= 0xDBFF) {
7098 icUInt16Number high = (*str - 0xD800) * 0x400;
7099 icUInt16Number low = *(str + 1) - 0xDC00;
7100 code32 = (low | high) + 0x10000;
7101 str += 2;
7102 }
7103
7104 //UTF-32 to UTF-8 -------
7105
7106 if (code32 <= 0x007F) {
7107 sText += (unsigned char)code32;
7108 }
7109 else if (code32 <= 0x07FF) {
7110 sText += (unsigned char)(((code32 >> 6) & 0x1F) | 0xC0);
7111 sText += (unsigned char)((code32 & 0x3F) | 0x80);
7112 }
7113 else if (code32 <= 0xFFFF) {
7114 sText += (unsigned char)(((code32 >> 12) & 0x0F) | 0xE0);
7115 sText += (unsigned char)(((code32 >> 6) & 0x3F) | 0x80);
7116 sText += (unsigned char)(((code32) & 0x3F) | 0x80);
7117 }
7118 else if (code32 <= 0x10FFFF) {
7119 sText += (unsigned char)(((code32 >> 18) & 0x07) | 0xF0);
7120 sText += (unsigned char)(((code32 >> 12) & 0x3F) | 0x80);
7121 sText += (unsigned char)(((code32 >> 6) & 0x3F) | 0x80);
7122 sText += (unsigned char)(((code32) & 0x3F) | 0x80);
7123 }
7124 }
7125
7126 return true;
7127}
unsigned long icUInt32Number
Definition icProfileHeader.h:262

References m_pBuf.

Referenced by CIccTagMultiLocalizedUnicode::Describe(), GetUtf8(), GetUtf8Size(), icGetTagText(), and main().

+ Here is the caller graph for this function:

◆ GetUtf8()

const icChar * CIccLocalizedUnicode::GetUtf8 ( icChar szBuf,
icUInt32Number  nBufSize 
)

Name: CIccLocalizedUnicode::GetUtf8

Purpose: Extracts the ANSI data buffer (from UTF-16BE)

Args: szBuf = pointer where the returned string buffer is to be stored nBufSize = size of the buffer to be extracted

Return: Pointer to the ANSI data string

7054{
7055 if (!szBuf || !nBufSize)
7056 return NULL;
7057
7058 std::string str;
7059 GetText(str);
7060
7061 if (nBufSize - 1 < str.size()) {
7062 memcpy(szBuf, str.c_str(), nBufSize - 1);
7063 szBuf[nBufSize] = 0;
7064 }
7065 else {
7066 strcpy(szBuf, str.c_str());
7067 }
7068
7069 return szBuf;
7070}
bool GetText(std::string &text)
Definition IccTagBasic.cpp:7083

References GetText().

+ Here is the call graph for this function:

◆ GetUtf8Size()

icUInt32Number CIccLocalizedUnicode::GetUtf8Size ( )

Name: CIccLocalizedUnicode::GetUtf8Size

Purpose: Returns the size of the ANSI data buffer

7032{
7033 std::string str;
7034 GetText(str);
7035
7036 return (icUInt32Number)str.size()+1;
7037}

References GetText().

+ Here is the call graph for this function:

◆ operator=() [1/4]

CIccLocalizedUnicode & CIccLocalizedUnicode::operator= ( const CIccLocalizedUnicode UnicodeText)

Name: CIccLocalizedUnicode::operator=

Purpose: Copy Operator

Args: UnicodeText = The CIccLocalizedUnicode object to be copied

6995{
6996 if (&UnicodeText == this)
6997 return *this;
6998
6999 if (SetSize(UnicodeText.GetLength())) {
7000 memcpy(m_pBuf, UnicodeText.GetBuf(), m_nLength*sizeof(icUInt16Number));
7001 }
7002 m_nLanguageCode = UnicodeText.m_nLanguageCode;
7003 m_nCountryCode = UnicodeText.m_nCountryCode;
7004
7005 return *this;
7006}
bool SetSize(icUInt32Number)
Definition IccTagBasic.cpp:7141

References GetBuf(), GetLength(), m_nCountryCode, m_nLanguageCode, m_nLength, m_pBuf, and SetSize().

+ Here is the call graph for this function:

◆ operator=() [2/4]

const icChar * CIccLocalizedUnicode::operator= ( const icChar szText)
inline
1196{ SetText(szText); return szText; }
bool SetText(const icChar *szText, icLanguageCode nLanguageCode=icLanguageCodeEnglish, icCountryCode nRegionCode=icCountryCodeUSA)
Definition IccTagBasic.cpp:7172

References SetText().

+ Here is the call graph for this function:

◆ operator=() [3/4]

const icUInt16Number * CIccLocalizedUnicode::operator= ( const icUInt16Number sszText)
inline
1197{ SetText(sszText); return sszText; }

References SetText().

+ Here is the call graph for this function:

◆ operator=() [4/4]

const icUInt32Number * CIccLocalizedUnicode::operator= ( const icUInt32Number sszText)
inline
1198{ SetText(sszText); return sszText; }

References SetText().

+ Here is the call graph for this function:

◆ SetSize()

bool CIccLocalizedUnicode::SetSize ( icUInt32Number  nSize)

Name: CIccLocalizedUnicode::SetSize

Purpose: Sets the size of the string buffer.

Args: nSize - length of the string

7142{
7143 if (nSize == m_nLength)
7144 return true;
7145
7146 m_pBuf = (icUInt16Number*)icRealloc(m_pBuf, (nSize+1)*sizeof(icUInt16Number));
7147
7148 if (!m_pBuf) {
7149 m_nLength = 0;
7150 return false;
7151 }
7152
7153 m_nLength = nSize;
7154
7155 m_pBuf[nSize]=0;
7156
7157 return true;
7158}
ICCPROFLIB_API void * icRealloc(void *ptr, size_t size)
Definition IccUtil.cpp:111

References icRealloc(), m_nLength, and m_pBuf.

Referenced by operator=(), CIccTagMultiLocalizedUnicode::Read(), SetText(), SetText(), and SetText().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SetText() [1/3]

bool CIccLocalizedUnicode::SetText ( const icChar szText,
icLanguageCode  nLanguageCode = icLanguageCodeEnglish,
icCountryCode  nRegionCode = icCountryCodeUSA 
)

Name: CIccLocalizedUnicode::SetText

Purpose: Allows text data associated with the tag to be set.

Args: szText = zero terminated utf8 string to put in tag, nLanguageCode = the language code type as defined by icLanguageCode, nRegionCode = the region code type as defined by icCountryCode

7175{
7176 if (!szText)
7177 szText = "";
7178
7179 //first convert utf8 to unicode
7180 std::vector<unsigned long> unicode;
7181 size_t i = 0;
7182 while (szText[i])
7183 {
7184 unsigned long uni;
7185 size_t todo;
7186 bool error = false;
7187 unsigned char ch = szText[i++];
7188 if (ch <= 0x7F)
7189 {
7190 uni = ch;
7191 todo = 0;
7192 }
7193 else if (ch <= 0xBF)
7194 {
7195 //not a UTF-8 string so use question mark
7196 uni = '?';
7197 todo = 0;
7198 }
7199 else if (ch <= 0xDF)
7200 {
7201 uni = ch & 0x1F;
7202 todo = 1;
7203 }
7204 else if (ch <= 0xEF)
7205 {
7206 uni = ch & 0x0F;
7207 todo = 2;
7208 }
7209 else if (ch <= 0xF7)
7210 {
7211 uni = ch & 0x07;
7212 todo = 3;
7213 }
7214 else
7215 {
7216 //not a UTF-8 string so use question mark
7217 uni = '?';
7218 todo = 0;;
7219 }
7220 for (size_t j = 0; j < todo; ++j)
7221 {
7222 if (!szText[i]) {
7223 uni = '?';
7224 break;
7225 }
7226 else {
7227 unsigned char ch = szText[i];
7228 if (ch < 0x80 || ch > 0xBF) {
7229 //not a UTF-8 string so use question mark
7230 uni = '?';
7231 break;
7232 }
7233 else {
7234 uni <<= 6;
7235 uni += ch & 0x3F;
7236 }
7237 }
7238 }
7239 if (uni >= 0xD800 && uni <= 0xDFFF) {
7240 //not a UTF-8 string so use question mark
7241 uni = '?';
7242 }
7243 else if (uni > 0x10FFFF) {
7244 //not a UTF-8 string so use question mark
7245 uni = '?';
7246 }
7247 unicode.push_back(uni);
7248 }
7249
7250 //now convert unicode to utf16
7251 std::vector<unsigned short> utf16;
7252 for (i = 0; i < unicode.size(); ++i)
7253 {
7254 unsigned long uni = unicode[i];
7255 if (uni <= 0xFFFF)
7256 {
7257 utf16.push_back((unsigned short)uni);
7258 }
7259 else
7260 {
7261 uni -= 0x10000;
7262 utf16.push_back((unsigned short)((uni >> 10) + 0xD800));
7263 utf16.push_back((unsigned short)((uni & 0x3FF) + 0xDC00));
7264 }
7265 }
7266
7267 icUInt16Number *pBuf;
7268
7269 size_t len = utf16.size();
7270 if (!SetSize((icUInt32Number)len+1))
7271 return false;
7272
7273 pBuf = m_pBuf;
7274 for (i=0; i<len; i++) {
7275 *pBuf++ = utf16[i];
7276 }
7277 *pBuf = 0;
7278
7279 m_nLanguageCode = nLanguageCode;
7280 m_nCountryCode = nRegionCode;
7281
7282 return true;
7283}

References m_nCountryCode, m_nLanguageCode, m_pBuf, and SetSize().

Referenced by operator=(), and CIccTagMultiLocalizedUnicode::SetText().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SetText() [2/3]

bool CIccLocalizedUnicode::SetText ( const icUInt16Number sszUnicode16Text,
icLanguageCode  nLanguageCode = icLanguageCodeEnglish,
icCountryCode  nRegionCode = icCountryCodeUSA 
)

Name: CIccLocalizedUnicode::SetText

Purpose: Allows text data associated with the tag to be set.

Args: sszUnicode16Text = Unicode16 text to be set, nLanguageCode = the language code type as defined by icLanguageCode, nRegionCode = the region code type as defined by icCountryCode

7300{
7301 icUInt16Number empty[1] = { 0 };
7302
7303 if (!sszUnicode16Text)
7304 sszUnicode16Text = &empty[0];
7305
7306 const icUInt16Number *pBuf=sszUnicode16Text;
7307 int len;
7308
7309 for (len=0; *pBuf; len++, pBuf++);
7310
7311 if (!SetSize(len))
7312 return false;
7313 memcpy(m_pBuf, sszUnicode16Text, (len+1)*sizeof(icUInt16Number));
7314
7315 m_nLanguageCode = nLanguageCode;
7316 m_nCountryCode = nRegionCode;
7317
7318 return true;
7319}

References m_nCountryCode, m_nLanguageCode, m_pBuf, and SetSize().

Referenced by operator=(), and CIccTagMultiLocalizedUnicode::SetText().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SetText() [3/3]

bool CIccLocalizedUnicode::SetText ( const icUInt32Number sszUnicode32Text,
icLanguageCode  nLanguageCode = icLanguageCodeEnglish,
icCountryCode  nRegionCode = icCountryCodeUSA 
)

Name: CIccLocalizedUnicode::SetText

Purpose: Allows text data associated with the tag to be set.

Args: sszUnicode32Text = Unicode32 text to be set, nLanguageCode = the language code type as defined by icLanguageCode, nRegionCode = the region code type as defined by icCountryCode

7336{
7337 const icUInt32Number empty[1] = { 0 };
7338 if (!sszUnicode32Text)
7339 sszUnicode32Text = &empty[0];
7340
7341 const icUInt32Number *pBuf=sszUnicode32Text;
7342 int len;
7343
7344 for (len=0; *pBuf; len++, pBuf++);
7345 if (*pBuf)
7346 pBuf--;
7347
7348 if (!SetSize(len*2))
7349 return false;
7350
7351 const icUInt32Number *srcStart = sszUnicode32Text;
7352 icUInt16Number *dstStart = m_pBuf;
7353 icConvertUTF32toUTF16(&srcStart, &srcStart[len], &dstStart, &dstStart[len*2], lenientConversion);
7354
7355 *dstStart=0;
7356 if (!SetSize((icUInt32Number)(dstStart - m_pBuf)))
7357 return false;
7358
7359 m_nLanguageCode = nLanguageCode;
7360 m_nCountryCode = nRegionCode;
7361
7362 return true;
7363}
@ lenientConversion
Definition IccConvertUTF.h:127
icUtfConversionResult icConvertUTF32toUTF16(const UTF32 **sourceStart, const UTF32 *sourceEnd, UTF16 **targetStart, UTF16 *targetEnd, icUtfConversionFlags flags)
Definition IccConvertUTF.cpp:61

References icConvertUTF32toUTF16(), lenientConversion, m_nCountryCode, m_nLanguageCode, m_pBuf, and SetSize().

Referenced by operator=(), and CIccTagMultiLocalizedUnicode::SetText().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ m_nCountryCode

◆ m_nLanguageCode

◆ m_nLength

icUInt32Number CIccLocalizedUnicode::m_nLength
protected

◆ m_pBuf


The documentation for this class was generated from the following files: