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 #if defined HAVE_CONFIG_H
00028 #include <config.h>
00029 #endif
00030
00031
00032
00033 #include <string.h>
00034 #include <stdlib.h>
00035 #include "field_impl.h"
00036 #include "utils.h"
00037 #include "io_helpers.h"
00038
00039 using namespace dami;
00040
00057 size_t ID3_FieldImpl::Set(const unicode_t* data)
00058 {
00059 size_t size = 0;
00060 if (this->GetType() == ID3FTY_TEXTSTRING &&
00061 this->GetEncoding() == ID3TE_UNICODE)
00062 {
00063 String text((const char*) data, ucslen(data) * 2);
00064 size = this->SetText_i(text);
00065 }
00066 return size;
00067 }
00068
00069 size_t ID3_FieldImpl::Add(const unicode_t* data)
00070 {
00071 size_t size = 0;
00072 if (this->GetType() == ID3FTY_TEXTSTRING &&
00073 this->GetEncoding() == ID3TE_UNICODE)
00074 {
00075 String text((const char*) data, ucslen(data) * 2);
00076 size = this->AddText_i(text);
00077 }
00078 return size;
00079 }
00080
00101 size_t ID3_FieldImpl::Get(unicode_t *buffer, size_t maxLength) const
00102 {
00103 size_t length = 0;
00104 if (this->GetType() == ID3FTY_TEXTSTRING &&
00105 this->GetEncoding() == ID3TE_UNICODE &&
00106 buffer != NULL && maxLength > 0)
00107 {
00108 size_t size = this->Size();
00109 length = dami::min(maxLength, size);
00110 ::memcpy((void *)buffer, (void *)_text.data(), length * 2);
00111 if (length < maxLength)
00112 {
00113 buffer[length] = NULL_UNICODE;
00114 }
00115 }
00116 return length;
00117 }
00118
00119 const unicode_t* ID3_FieldImpl::GetRawUnicodeText() const
00120 {
00121 const unicode_t* text = NULL;
00122 if (this->GetType() == ID3FTY_TEXTSTRING &&
00123 this->GetEncoding() == ID3TE_UNICODE)
00124 {
00125 text = (unicode_t *)_text.data();
00126 }
00127 return text;
00128 }
00129
00130 const unicode_t* ID3_FieldImpl::GetRawUnicodeTextItem(index_t index) const
00131 {
00132 const unicode_t* text = NULL;
00133 if (this->GetType() == ID3FTY_TEXTSTRING &&
00134 this->GetEncoding() == ID3TE_ASCII &&
00135 index < this->GetNumTextItems())
00136 {
00137 String unicode = _text + '\0' + '\0';
00138 text = (unicode_t *) unicode.data();
00139 for (size_t i = 0; i < index; ++i)
00140 {
00141 text += ucslen(text) + 1;
00142 }
00143 }
00144 return text;
00145 }
00146
00147 size_t ID3_FieldImpl::Get(unicode_t *buffer, size_t maxLength, index_t itemNum) const
00148 {
00149 size_t length = 0;
00150 size_t total_items = this->GetNumTextItems();
00151 if (this->GetType() == ID3FTY_TEXTSTRING &&
00152 this->GetEncoding() == ID3TE_UNICODE &&
00153 buffer != NULL && maxLength > 0 && itemNum < total_items)
00154 {
00155 const unicode_t* text = this->GetRawUnicodeTextItem(itemNum);
00156 if (NULL != text)
00157 {
00158 size_t length = dami::min(maxLength, ucslen(text));
00159 ::memcpy(buffer, text, length * 2);
00160 if (length < maxLength)
00161 {
00162 buffer[length] = NULL_UNICODE;
00163 }
00164 }
00165 }
00166
00167 return length;
00168 }
00169
00170