本文整理汇总了C++中AString::assign方法的典型用法代码示例。如果您正苦于以下问题:C++ AString::assign方法的具体用法?C++ AString::assign怎么用?C++ AString::assign使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AString
的用法示例。
在下文中一共展示了AString::assign方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testJustify
void testJustify()
{
AString str;
str.assign("2f8");
str.justifyRight(4, '0');
std::cout << str << std::endl;
str.justifyRight(8, '0');
std::cout << str << std::endl;
str.justifyRight(3, '0');
std::cout << str << std::endl;
str.assign("2f8");
str.justifyCenter(8, '0');
std::cout << str << std::endl;
str.justifyCenter(11, '0');
std::cout << str << std::endl;
str.assign("2f8");
str.justifyCenter(11, '0');
std::cout << str << std::endl;
}
示例2: testJustify
void testJustify(int& iRet)
{
AString str;
str.assign("2f8");
str.justifyRight(4, '0');
ASSERT_UNIT_TEST(str.equals("02f8"), "AString::justifyRight", "0", iRet);
str.justifyRight(8, '0');
ASSERT_UNIT_TEST(str.equals("000002f8"), "AString::justifyRight", "1", iRet);
str.justifyRight(3, '0');
ASSERT_UNIT_TEST(str.equals("000002f8"), "AString::justifyRight", "2", iRet);
str.assign("2f8");
str.justifyCenter(8, '0');
ASSERT_UNIT_TEST(str.equals("0002f800"), "AString::justifyCenter", "0", iRet);
str.justifyCenter(11, '0');
ASSERT_UNIT_TEST(str.equals("000002f8000"), "AString::justifyCenter", "1", iRet);
str.assign("2f8");
str.justifyCenter(11, '0');
ASSERT_UNIT_TEST(str.equals("00002f80000"), "AString::justifyCenter", "2", iRet);
str.justifyCenter(5, '0');
ASSERT_UNIT_TEST(str.equals("00002f80000"), "AString::justifyCenter", "3", iRet);
str.assign("2f8");
str.justifyLeft(7, '0');
ASSERT_UNIT_TEST(str.equals("2f80000"), "AString::justifyLeft", "0", iRet);
str.justifyLeft(5, '0');
ASSERT_UNIT_TEST(str.equals("2f80000"), "AString::justifyLeft", "1", iRet);
}
示例3: ReadRestOfFile
int cFile::ReadRestOfFile(AString & a_Contents)
{
ASSERT(IsOpen());
if (!IsOpen())
{
return -1;
}
long TotalSize = GetSize();
if (TotalSize < 0)
{
return -1;
}
long Position = Tell();
if (Position < 0)
{
return -1;
}
auto DataSize = static_cast<size_t>(TotalSize - Position);
// HACK: This depends on the internal knowledge that AString's data() function returns the internal buffer directly
a_Contents.assign(DataSize, '\0');
return Read(reinterpret_cast<void *>(const_cast<char *>(a_Contents.data())), DataSize);
}
示例4: UpdateAddress
void cTCPLinkImpl::UpdateAddress(const sockaddr * a_Address, socklen_t a_AddrLen, AString & a_IP, UInt16 & a_Port)
{
// Based on the family specified in the address, use the correct datastructure to convert to IP string:
char IP[128];
switch (a_Address->sa_family)
{
case AF_INET: // IPv4:
{
const sockaddr_in * sin = reinterpret_cast<const sockaddr_in *>(a_Address);
evutil_inet_ntop(AF_INET, &(sin->sin_addr), IP, sizeof(IP));
a_Port = ntohs(sin->sin_port);
break;
}
case AF_INET6: // IPv6
{
const sockaddr_in6 * sin = reinterpret_cast<const sockaddr_in6 *>(a_Address);
evutil_inet_ntop(AF_INET6, &(sin->sin6_addr), IP, sizeof(IP));
a_Port = ntohs(sin->sin6_port);
break;
}
default:
{
LOGWARNING("%s: Unknown socket address family: %d", __FUNCTION__, a_Address->sa_family);
ASSERT(!"Unknown socket address family");
break;
}
}
a_IP.assign(IP);
}
示例5: ReadString
bool cByteBuffer::ReadString(AString & a_String, int a_Count)
{
CHECK_THREAD;
CheckValid();
ASSERT(a_Count >= 0);
NEEDBYTES(a_Count);
a_String.clear();
a_String.reserve(a_Count);
int BytesToEndOfBuffer = m_BufferSize - m_ReadPos;
ASSERT(BytesToEndOfBuffer >= 0); // Sanity check
if (BytesToEndOfBuffer <= a_Count)
{
// Reading across the ringbuffer end, read the first part and adjust parameters:
if (BytesToEndOfBuffer > 0)
{
a_String.assign(m_Buffer + m_ReadPos, BytesToEndOfBuffer);
a_Count -= BytesToEndOfBuffer;
}
m_ReadPos = 0;
}
// Read the rest of the bytes in a single read (guaranteed to fit):
if (a_Count > 0)
{
a_String.append(m_Buffer + m_ReadPos, a_Count);
m_ReadPos += a_Count;
}
return true;
}
示例6:
bool cWSSCompact::cPAKFile::GetChunkData(const cChunkCoords & a_Chunk, int & a_UncompressedSize, AString & a_Data)
{
int ChunkX = a_Chunk.m_ChunkX;
int ChunkZ = a_Chunk.m_ChunkZ;
sChunkHeader * Header = NULL;
int Offset = 0;
for (sChunkHeaders::iterator itr = m_ChunkHeaders.begin(); itr != m_ChunkHeaders.end(); ++itr)
{
if (((*itr)->m_ChunkX == ChunkX) && ((*itr)->m_ChunkZ == ChunkZ))
{
Header = *itr;
break;
}
Offset += (*itr)->m_CompressedSize;
}
if ((Header == NULL) || (Offset + Header->m_CompressedSize > (int)m_DataContents.size()))
{
// Chunk not found / data invalid
return false;
}
a_UncompressedSize = Header->m_UncompressedSize;
a_Data.assign(m_DataContents, Offset, Header->m_CompressedSize);
return true;
}
示例7: ut_ATextConverter_General
int ut_ATextConverter_General()
{
std::cerr << "ut_ATextConverter_General" << std::endl;
int iRet = 0x0;
AString result;
AString str("!<HTML>&...");
ATextConverter::makeHtmlSafe(str, result);
ASSERT_UNIT_TEST(result.equals("!<HTML>&..."), "ATextConverter::makeHtmlSafe", "0", iRet);
result.clear();
str.assign("<><HTML>&...&");
ATextConverter::makeHtmlSafe(str, result);
ASSERT_UNIT_TEST(result.equals("<><HTML>&...&"), "ATextConverter::makeHtmlSafe", "1", iRet);
//a_Round trips
AString strR;
str = "±(S3t¯th3~co^tro|[email protected]~of~the¯sµ^!)²÷exit`";
result.clear();
ATextConverter::encodeHEX(str, strR);
ATextConverter::decodeHEX(strR, result);
ASSERT_UNIT_TEST(result.equals(str), "HEX roudtrip", "", iRet);
strR.clear();
result.clear();
ATextConverter::encodeURL(str, strR);
ATextConverter::decodeURL(strR, result);
ASSERT_UNIT_TEST(result.equals(str), "URL roudtrip", "", iRet);
strR.clear();
result.clear();
ATextConverter::encodeBase64(str, strR);
ATextConverter::decodeBase64(strR, result);
ASSERT_UNIT_TEST(result.equals(str), "Base64 roudtrip", "", iRet);
strR.clear();
result.clear();
ATextConverter::encode64(str, strR);
ATextConverter::decode64(strR, result);
ASSERT_UNIT_TEST(result.equals(str), "encode64 roudtrip", "", iRet);
//a_Base64
result.clear();
ATextConverter::encodeBase64("foo:bar", result);
ASSERT_UNIT_TEST(result.equals("Zm9vOmJhcg=="), "Base64 encode", "", iRet);
result.clear();
ATextConverter::decodeBase64("Zm9vOmJhcg==", result);
ASSERT_UNIT_TEST(result.equals("foo:bar"), "Base64 decode", "", iRet);
//a_CData safe
str.assign("!INVALID]]> CData string! ]]> !");
strR.assign("!INVALID%5d%5d%3e CData string! %5d%5d%3e !");
result.clear();
ATextConverter::makeCDataSafe(str, result);
ASSERT_UNIT_TEST(result.equals(strR), "makeCDataSafe", "", iRet);
return iRet;
}
示例8: ToString
void cLuaState::ToString(int a_StackPos, AString & a_String)
{
size_t len;
const char * s = lua_tolstring(m_LuaState, a_StackPos, &len);
if (s != nullptr)
{
a_String.assign(s, len);
}
}
示例9: GetStackValue
void cLuaState::GetStackValue(int a_StackPos, AString & a_Value)
{
size_t len = 0;
const char * data = lua_tolstring(m_LuaState, a_StackPos, &len);
if (data != nullptr)
{
a_Value.assign(data, len);
}
}
示例10: CompressString
bool cWSSCompact::cPAKFile::SaveChunkToData(const cChunkCoords & a_Chunk, cWorld * a_World)
{
// Serialize the chunk:
cJsonChunkSerializer Serializer;
if (!a_World->GetChunkData(a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ, Serializer))
{
// Chunk not valid
LOG("cWSSCompact: Trying to save chunk [%d, %d, %d] that has no data, ignoring request.", a_Chunk.m_ChunkX, a_Chunk.m_ChunkY, a_Chunk.m_ChunkZ);
return false;
}
AString Data;
Data.assign((const char *)Serializer.GetBlockData(), cChunkDef::BlockDataSize);
if (Serializer.HasJsonData())
{
AString JsonData;
Json::StyledWriter writer;
JsonData = writer.write(Serializer.GetRoot());
Data.append(JsonData);
}
// Compress the data:
AString CompressedData;
int errorcode = CompressString(Data.data(), Data.size(), CompressedData, m_CompressionFactor);
if ( errorcode != Z_OK )
{
LOGERROR("Error %i compressing data for chunk [%d, %d, %d]", errorcode, a_Chunk.m_ChunkX, a_Chunk.m_ChunkY, a_Chunk.m_ChunkZ);
return false;
}
// Erase any existing data for the chunk:
EraseChunkData(a_Chunk);
// Save the header:
sChunkHeader * Header = new sChunkHeader;
if (Header == NULL)
{
LOGWARNING("Cannot create a new chunk header to save chunk [%d, %d, %d]", a_Chunk.m_ChunkX, a_Chunk.m_ChunkY, a_Chunk.m_ChunkZ);
return false;
}
Header->m_CompressedSize = (int)CompressedData.size();
Header->m_ChunkX = a_Chunk.m_ChunkX;
Header->m_ChunkZ = a_Chunk.m_ChunkZ;
Header->m_UncompressedSize = (int)Data.size();
m_ChunkHeaders.push_back(Header);
m_DataContents.append(CompressedData.data(), CompressedData.size());
m_NumDirty++;
return true;
}
示例11: ntohl
bool cWSSAnvil::cMCAFile::GetChunkData(const cChunkCoords & a_Chunk, AString & a_Data)
{
if (!OpenFile(true))
{
return false;
}
int LocalX = a_Chunk.m_ChunkX % 32;
if (LocalX < 0)
{
LocalX = 32 + LocalX;
}
int LocalZ = a_Chunk.m_ChunkZ % 32;
if (LocalZ < 0)
{
LocalZ = 32 + LocalZ;
}
unsigned ChunkLocation = ntohl(m_Header[LocalX + 32 * LocalZ]);
unsigned ChunkOffset = ChunkLocation >> 8;
m_File.Seek(ChunkOffset * 4096);
int ChunkSize = 0;
if (m_File.Read(&ChunkSize, 4) != 4)
{
return false;
}
ChunkSize = ntohl(ChunkSize);
char CompressionType = 0;
if (m_File.Read(&CompressionType, 1) != 1)
{
return false;
}
if (CompressionType != 2)
{
// Chunk is in an unknown compression
return false;
}
ChunkSize--;
// HACK: This depends on the internal knowledge that AString's data() function returns the internal buffer directly
a_Data.assign(ChunkSize, '\0');
return (m_File.Read((void *)a_Data.data(), ChunkSize) == ChunkSize);
}
示例12: LogStack
void cLuaState::LogStack(lua_State * a_LuaState, const char * a_Header)
{
// Format string consisting only of %s is used to appease the compiler
LOG("%s", (a_Header != nullptr) ? a_Header : "Lua C API Stack contents:");
for (int i = lua_gettop(a_LuaState); i > 0; i--)
{
AString Value;
int Type = lua_type(a_LuaState, i);
switch (Type)
{
case LUA_TBOOLEAN: Value.assign((lua_toboolean(a_LuaState, i) != 0) ? "true" : "false"); break;
case LUA_TLIGHTUSERDATA: Printf(Value, "%p", lua_touserdata(a_LuaState, i)); break;
case LUA_TNUMBER: Printf(Value, "%f", static_cast<double>(lua_tonumber(a_LuaState, i))); break;
case LUA_TSTRING: Printf(Value, "%s", lua_tostring(a_LuaState, i)); break;
case LUA_TTABLE: Printf(Value, "%p", lua_topointer(a_LuaState, i)); break;
default: break;
}
LOGD(" Idx %d: type %d (%s) %s", i, Type, lua_typename(a_LuaState, Type), Value.c_str());
} // for i - stack idx
}
示例13: getFields
bool AMySQLServer::getFields(const AString& table, VECTOR_AString& sv, AString& error)
{
if (!isInitialized())
{
error.assign("Database has not been initialized;");
return false;
}
if (table.isEmpty())
{
error = "Please use a namespace;";
return false;
}
sv.clear();
AString query("SHOW COLUMNS FROM `");
query += table;
query += "`";
MYSQL_RES *pmyresult = executeSQL(query, error);
if (pmyresult)
{
MYSQL_ROW myrow;
int iSize = (int)mysql_num_rows(pmyresult);
for (int i=0; i < iSize; ++i)
{
myrow = mysql_fetch_row(pmyresult);
if (myrow)
{
sv.push_back(myrow[0]);
}
}
mysql_free_result(pmyresult);
}
else
return false;
return true;
}
示例14: getTables
bool AMySQLServer::getTables(VECTOR_AString& sv, AString& error)
{
if (!isInitialized())
{
error.assign("Database has not been initialized;");
return false;
}
sv.clear();
MYSQL_RES *pmyresult = mysql_list_tables(mp_mydata, NULL);
if (pmyresult)
{
MYSQL_ROW myrow;
int iSize = (int)mysql_num_rows(pmyresult);
for (int i=0; i < iSize; ++i)
{
myrow = mysql_fetch_row(pmyresult);
if (myrow)
{
sv.push_back(myrow[0]);
}
}
mysql_free_result(pmyresult);
}
else
{
error = "Error(";
error += mysql_error(mp_mydata);
error += ") looking for tables;";
return false;
}
return true;
}
示例15: Converted
void cWSSCompact::cPAKFile::UpdateChunk2To3()
{
int Offset = 0;
AString NewDataContents;
int ChunksConverted = 0;
for (sChunkHeaders::iterator itr = m_ChunkHeaders.begin(); itr != m_ChunkHeaders.end(); ++itr)
{
sChunkHeader * Header = *itr;
if( ChunksConverted % 32 == 0 )
{
LOGINFO("Updating \"%s\" version 2 to version 3: " SIZE_T_FMT " %%", m_FileName.c_str(), (ChunksConverted * 100) / m_ChunkHeaders.size() );
}
ChunksConverted++;
AString Data;
int UncompressedSize = Header->m_UncompressedSize;
Data.assign(m_DataContents, Offset, Header->m_CompressedSize);
Offset += Header->m_CompressedSize;
// Crude data integrity check:
const int ExpectedSize = (16*256*16)*2 + (16*256*16)/2; // For version 2
if (UncompressedSize < ExpectedSize)
{
LOGWARNING("Chunk [%d, %d] has too short decompressed data (%d bytes out of %d needed), erasing",
Header->m_ChunkX, Header->m_ChunkZ,
UncompressedSize, ExpectedSize
);
Offset += Header->m_CompressedSize;
continue;
}
// Decompress the data:
AString UncompressedData;
{
int errorcode = UncompressString(Data.data(), Data.size(), UncompressedData, UncompressedSize);
if (errorcode != Z_OK)
{
LOGERROR("Error %d decompressing data for chunk [%d, %d]",
errorcode,
Header->m_ChunkX, Header->m_ChunkZ
);
Offset += Header->m_CompressedSize;
continue;
}
}
if (UncompressedSize != (int)UncompressedData.size())
{
LOGWARNING("Uncompressed data size differs (exp %d bytes, got " SIZE_T_FMT ") for chunk [%d, %d]",
UncompressedSize, UncompressedData.size(),
Header->m_ChunkX, Header->m_ChunkZ
);
Offset += Header->m_CompressedSize;
continue;
}
char ConvertedData[ExpectedSize];
memset(ConvertedData, 0, ExpectedSize);
// Cannot use cChunk::MakeIndex because it might change again?????????
// For compatibility, use what we know is current
#define MAKE_3_INDEX( x, y, z ) ( x + (z * 16) + (y * 16 * 16) )
unsigned int InChunkOffset = 0;
for( int x = 0; x < 16; ++x ) for( int z = 0; z < 16; ++z ) for( int y = 0; y < 256; ++y ) // YZX Loop order is important, in 1.1 Y was first then Z then X
{
ConvertedData[ MAKE_3_INDEX(x, y, z) ] = UncompressedData[InChunkOffset];
++InChunkOffset;
} // for y, z, x
unsigned int index2 = 0;
for( int x = 0; x < 16; ++x ) for( int z = 0; z < 16; ++z ) for( int y = 0; y < 256; ++y )
{
ConvertedData[ InChunkOffset + MAKE_3_INDEX(x, y, z)/2 ] |= ( (UncompressedData[ InChunkOffset + index2/2 ] >> ((index2&1)*4) ) & 0x0f ) << ((x&1)*4);
++index2;
}
InChunkOffset += index2 / 2;
index2 = 0;
for( int x = 0; x < 16; ++x ) for( int z = 0; z < 16; ++z ) for( int y = 0; y < 256; ++y )
{
ConvertedData[ InChunkOffset + MAKE_3_INDEX(x, y, z)/2 ] |= ( (UncompressedData[ InChunkOffset + index2/2 ] >> ((index2&1)*4) ) & 0x0f ) << ((x&1)*4);
++index2;
}
InChunkOffset += index2 / 2;
index2 = 0;
for( int x = 0; x < 16; ++x ) for( int z = 0; z < 16; ++z ) for( int y = 0; y < 256; ++y )
{
ConvertedData[ InChunkOffset + MAKE_3_INDEX(x, y, z)/2 ] |= ( (UncompressedData[ InChunkOffset + index2/2 ] >> ((index2&1)*4) ) & 0x0f ) << ((x&1)*4);
++index2;
}
InChunkOffset += index2 / 2;
AString Converted(ConvertedData, ExpectedSize);
// Add JSON data afterwards
if (UncompressedData.size() > InChunkOffset)
//.........这里部分代码省略.........