本文整理汇总了C++中String::Allocate方法的典型用法代码示例。如果您正苦于以下问题:C++ String::Allocate方法的具体用法?C++ String::Allocate怎么用?C++ String::Allocate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类String
的用法示例。
在下文中一共展示了String::Allocate方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Insert
String & String::Insert(float f, int index)
{
String string;
string.Allocate(64);
string.Format("%g",f);
return Insert(string,index);
}
示例2: Erase
String String::Erase(const int pos, int len)
{
int str_len = Size();
int len_a = pos;
// If erase after the length of the string, return.
if (len_a >= str_len)
return *this;
// Prevent erasing after the end of the string.
if ((len_a + len) > str_len) {
// Resize the erase length.
len = str_len - len_a;
}
String s;
int len_b = str_len - len_a - len;
s.Allocate(len_a + len_b + 1);
Copy(&s.v[0], &v[0], len_a);
if (len_b > 0) {
int offset_b = len_a + len;
Concatenate(&s.v[0], &v[0 + offset_b]);
}
s.v[s.Size()] = 0;
v = s.v;
return *this;
}
示例3: Construct
String & String::Construct(float f)
{
String string;
string.Allocate(64);
string.Format("%g",f);
return Construct(string);
}
示例4: Replace
String & String::Replace(double d)
{
String string;
string.Allocate(512);
string.Format("%f",d);
return Replace(string);
}
示例5: Prepend
String & String::Prepend(double d)
{
String string;
string.Allocate(512);
string.Format("%f",d);
return Prepend(string);
}
示例6: UnsignedIntAsHex
String String::UnsignedIntAsHex(UINT Value)
{
String S;
S.Allocate(20);
sprintf(S.CString(), "%x", Value);
S.ResizeToCStringLength();
return S;
}
示例7: ToLower
String String::ToLower() const
{
String result;
if (HasChars())
{
result.Allocate(Length());
Algo::Range::Transform(Begin(), End(), result.MutableBegin(), Algo::Function::FunctorFromMemberRef(&Char::ToLower));
}
return result;
}
示例8: Pad
String String::Pad(const Char& ch, Size left, Size right) const
{
String result;
if (Length() + left + right > 0)
{
result.Allocate(Length() + left + right);
Iterator dest = result.MutableBegin();
dest = Algo::Range::FillFirst(dest, left, ch);
dest = Algo::Range::Copy(Begin(), End(), dest);
Algo::Range::Fill(dest, result.MutableEnd(), ch);
}
return result;
}
示例9: Concat
String String::Concat(const String& str) const
{
String result;
if (HasChars() || str.HasChars())
{
result.Allocate(Length() + str.Length());
Iterator dest = Algo::Range::Copy(Begin(), End(), result.MutableBegin());
Algo::Range::Copy(str.Begin(), str.End(), dest);
}
return result;
}
示例10:
//string operations
String operator + (const String& l, const String& r)
{
String result;
const UINT length = l._Length + r._Length;
result.Allocate(length + 1);
result._Length = length;
result._Data[length] = '\0';
if(l._Length > 0)
memcpy( result._Data, l._Data, l._Length);
if(r._Length > 0)
memcpy( result._Data + l._Length, r._Data, r._Length);
return result;
}
示例11: memcpy
String operator + (const String &L, const String &R)
{
String Result;
const UINT TotalLength = L._Length + R._Length;
Result.Allocate(TotalLength + 1);
Result._Length = TotalLength;
Result._Data[TotalLength] = '\0';
if(L._Length > 0)
{
memcpy(Result._Data, L._Data, L._Length);
}
if(R._Length > 0)
{
memcpy(Result._Data + L._Length, R._Data, R._Length);
}
return Result;
}
示例12: ByteStreamToHexString
String String::ByteStreamToHexString(const BYTE *stream, UINT count)
{
static const char table[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
String result;
result.Allocate(count * 2 + 1);
result._Length = count * 2;
char *resultData = result._Data;
UINT stringIndex = 0;
for(UINT byteIndex = 0; byteIndex < count; byteIndex++)
{
const BYTE curByte = stream[byteIndex];
resultData[stringIndex++] = table[ curByte & 0x0F];
resultData[stringIndex++] = table[(curByte >> 4) & 0x0F];
}
resultData[stringIndex++] = '\0';
return result;
}
示例13: Reverse
String String::Reverse() const
{
if (Length() < 2)
{
return String(*this);
}
String result;
result.Allocate(Length());
Iterator dest = result.MutableEnd();
for (ConstIterator src = Begin(); src != End(); ++src)
{
--dest;
*dest = *src;
}
return result;
}