Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "field_impl.h"
00028 #include "id3/utils.h"
00029 #include "io_helpers.h"
00030
00031 using namespace dami;
00032
00049 size_t ID3_FieldImpl::Set(const unicode_t* data)
00050 {
00051 size_t size = 0;
00052 if (this->GetType() == ID3FTY_TEXTSTRING &&
00053 this->GetEncoding() == ID3TE_UNICODE && data)
00054 {
00055 String text((const char*) data, ucslen(data) * 2);
00056 size = this->SetText_i(text);
00057 }
00058 return size;
00059 }
00060
00061 size_t ID3_FieldImpl::Add(const unicode_t* data)
00062 {
00063 size_t size = 0;
00064 if (this->GetType() == ID3FTY_TEXTSTRING &&
00065 this->GetEncoding() == ID3TE_UNICODE)
00066 {
00067 String text((const char*) data, ucslen(data) * 2);
00068 size = this->AddText_i(text);
00069 }
00070 return size;
00071 }
00072
00093 size_t ID3_FieldImpl::Get(unicode_t *buffer, size_t maxLength) const
00094 {
00095 size_t length = 0;
00096 if (this->GetType() == ID3FTY_TEXTSTRING &&
00097 this->GetEncoding() == ID3TE_UNICODE &&
00098 buffer != NULL && maxLength > 0)
00099 {
00100 size_t size = this->Size();
00101 length = dami::min(maxLength, size);
00102 ::memcpy((void *)buffer, (void *)_text.data(), length * 2);
00103 if (length < maxLength)
00104 {
00105 buffer[length] = NULL_UNICODE;
00106 }
00107 }
00108 return length;
00109 }
00110
00111 const unicode_t* ID3_FieldImpl::GetRawUnicodeText() const
00112 {
00113 const unicode_t* text = NULL;
00114 if (this->GetType() == ID3FTY_TEXTSTRING &&
00115 this->GetEncoding() == ID3TE_UNICODE)
00116 {
00117 text = (unicode_t *)_text.data();
00118 }
00119 return text;
00120 }
00121
00122 const unicode_t* ID3_FieldImpl::GetRawUnicodeTextItem(size_t index) const
00123 {
00124 const unicode_t* text = NULL;
00125 if (this->GetType() == ID3FTY_TEXTSTRING &&
00126 this->GetEncoding() == ID3TE_UNICODE &&
00127 index < this->GetNumTextItems())
00128 {
00129 String unicode = _text + '\0' + '\0';
00130 text = (unicode_t *) unicode.data();
00131 for (size_t i = 0; i < index; ++i)
00132 {
00133 text += ucslen(text) + 1;
00134 }
00135 }
00136 return text;
00137 }
00138
00139 size_t ID3_FieldImpl::Get(unicode_t *buffer, size_t maxLength, size_t itemNum) const
00140 {
00141 size_t length = 0;
00142 size_t total_items = this->GetNumTextItems();
00143 if (this->GetType() == ID3FTY_TEXTSTRING &&
00144 this->GetEncoding() == ID3TE_UNICODE &&
00145 buffer != NULL && maxLength > 0 && itemNum < total_items)
00146 {
00147 const unicode_t* text = this->GetRawUnicodeTextItem(itemNum);
00148 if (NULL != text)
00149 {
00150 size_t length = dami::min(maxLength, ucslen(text));
00151 ::memcpy(buffer, text, length * 2);
00152 if (length < maxLength)
00153 {
00154 buffer[length] = NULL_UNICODE;
00155 }
00156 }
00157 }
00158
00159 return length;
00160 }
00161
00162