string.cpp revision 76a1b5545b9d2163fd30824791f7f78650c238ec
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * MS COM / XPCOM Abstraction Layer:
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * UTF-8 and UTF-16 string classes
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * Copyright (C) 2006-2007 Oracle Corporation
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * available from http://www.virtualbox.org. This file is free software;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * you can redistribute it and/or modify it under the terms of the GNU
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * General Public License (GPL) as published by the Free Software
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync// BSTR representing a null wide char with 32 bits of length prefix (0);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync// this will work on Windows as well as other platforms where BSTR does
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync// not use length prefixes
4328e87247f4a96449677e199c7e99ef516fc1cevboxsyncconst BSTR g_bstrEmpty = (BSTR)(&g_achEmptyBstr[2]);
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync/* static */
9ce5d949e4f1572d445a5c0aecabe9de8b672c99vboxsync/* static */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsyncconst Utf8Str Utf8Str::Empty; /* default ctor is OK */
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync return *this;
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync return *this;
89aedeb1d8af54aba6ae46dbbd256281315c1be6vboxsync * Internal function used in Utf8Str copy constructors and assignment when
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * copying from a UTF-16 string.
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * As with the iprt::ministring::copyFrom() variants, this unconditionally
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * sets the members to a copy of the given other strings and makes
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * no assumptions about previous contents. This can therefore be used
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * both in copy constructors, when member variables have no defined
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * value, and in assignments after having called cleanup().
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * This variant converts from a UTF-16 string, most probably from
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync * a Bstr assignment.
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync if (s && *s)
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync int vrc = RTUtf16ToUtf8Ex((PRTUTF16)s, // PCRTUTF16 pwszString
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync RTSTR_MAX, // size_t cwcString: translate entire string
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync 0, // size_t cch: if 0, func allocates buffer in *ppsz
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync &m_cbLength); // size_t *pcch: receives the size of the output string, excluding the terminator.
4328e87247f4a96449677e199c7e99ef516fc1cevboxsync // @todo what do we do with bad input strings? throw also? for now just keep an empty string
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsyncvoid Utf8StrFmt::init(const char *format, va_list args)
6e12ccc60ac657fb87e27b7a2b26e0a63bebe024vboxsync} /* namespace com */