1 /**
2 * @file MStringList.cpp
3 * @brief List of String objects
4 *
5 * (c) 2013-2014 by Mega Limited, Auckland, New Zealand
6 *
7 * This file is part of the MEGA SDK - Client Access Engine.
8 *
9 * Applications using the MEGA API must present a valid application key
10 * and comply with the the rules set forth in the Terms of Service.
11 *
12 * The MEGA SDK is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 *
16 * @copyright Simplified (2-clause) BSD License.
17 *
18 * You should have received a copy of the license along with this
19 * program.
20 */
21 
22 #include "MStringList.h"
23 
24 using namespace mega;
25 using namespace Platform;
26 
MStringList(MegaStringList * stringList,bool cMemoryOwn)27 MStringList::MStringList(MegaStringList *stringList, bool cMemoryOwn)
28 {
29     this->stringList = stringList;
30     this->cMemoryOwn = cMemoryOwn;
31 }
32 
~MStringList()33 MStringList::~MStringList()
34 {
35     if (cMemoryOwn)
36         delete stringList;
37 }
38 
39 String^ MStringList::get(int i)
40 {
41     std::string utf16string;
42     const char *utf8string = stringList->get(i);
43     if (!utf8string)
44         return nullptr;
45 
46     MegaApi::utf8ToUtf16(utf8string, &utf16string);
47     delete[] utf8string;
48 
49     return stringList ? ref new String((wchar_t *)utf16string.data()) : nullptr;
50 }
51 
size()52 int MStringList::size()
53 {
54     return stringList ? stringList->size() : 0;
55 }
56