Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

src/field_string_unicode.cpp

Go to the documentation of this file.
00001 // $Id: field_string_unicode.cpp,v 1.30 2000/10/29 01:37:28 eldamitri Exp $
00002 
00003 // id3lib: a C++ library for creating and manipulating id3v1/v2 tags
00004 // Copyright 1999, 2000  Scott Thomas Haug
00005 
00006 // This library is free software; you can redistribute it and/or modify it
00007 // under the terms of the GNU Library General Public License as published by
00008 // the Free Software Foundation; either version 2 of the License, or (at your
00009 // option) any later version.
00010 //
00011 // This library is distributed in the hope that it will be useful, but WITHOUT
00012 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00013 // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00014 // License for more details.
00015 //
00016 // You should have received a copy of the GNU Library General Public License
00017 // along with this library; if not, write to the Free Software Foundation,
00018 // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00019 
00020 // The id3lib authors encourage improvements and optimisations to be sent to
00021 // the id3lib coordinator.  Please see the README file for details on where to
00022 // send such submissions.  See the AUTHORS file for a list of people who have
00023 // contributed to id3lib.  See the ChangeLog file for a list of changes to
00024 // id3lib.  These files are distributed with id3lib at
00025 // http://download.sourceforge.net/id3lib/
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 

Generated at Sat Sep 8 15:51:08 2001 for id3lib by doxygen1.2.8 written by Dimitri van Heesch, © 1997-2001