Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/ps/CStr.cpp
/* Copyright (C) 2019 Wildfire Games. | /* Copyright (C) 2020 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
▲ Show 20 Lines • Show All 452 Lines • ▼ Show 20 Lines | for (i = 0; i < len; i++) | ||||
*(u16 *)(buffer + i*2) = bigEndian; | *(u16 *)(buffer + i*2) = bigEndian; | ||||
} | } | ||||
*(u16 *)(buffer + i*2) = 0; | *(u16 *)(buffer + i*2) = 0; | ||||
return buffer + len*2 + 2; | return buffer + len*2 + 2; | ||||
} | } | ||||
const u8* CStrW::Deserialize(const u8* buffer, const u8* bufferend) | const u8* CStrW::Deserialize(const u8* buffer, const u8* bufferend) | ||||
{ | { | ||||
ENSURE(buffer); | |||||
ENSURE(bufferend); | |||||
const u16 *strend = (const u16 *)buffer; | const u16 *strend = (const u16 *)buffer; | ||||
while ((const u8 *)strend < bufferend && *strend) strend++; | while ((const u8 *)strend < bufferend && *strend) strend++; | ||||
if ((const u8 *)strend >= bufferend) return NULL; | if ((const u8 *)strend >= bufferend) return NULL; | ||||
resize(strend - (const u16 *)buffer); | resize(strend - (const u16 *)buffer); | ||||
const u16 *ptr = (const u16 *)buffer; | const u16 *ptr = (const u16 *)buffer; | ||||
std::wstring::iterator str = begin(); | std::wstring::iterator str = begin(); | ||||
Show All 24 Lines | u8* CStr8::Serialize(u8* buffer) const | ||||
size_t i = 0; | size_t i = 0; | ||||
for (i = 0; i < len; i++) | for (i = 0; i < len; i++) | ||||
buffer[i] = (*this)[i]; | buffer[i] = (*this)[i]; | ||||
return buffer + len; | return buffer + len; | ||||
} | } | ||||
const u8* CStr8::Deserialize(const u8* buffer, const u8* bufferend) | const u8* CStr8::Deserialize(const u8* buffer, const u8* bufferend) | ||||
{ | { | ||||
ENSURE(buffer); | |||||
ENSURE(bufferend); | |||||
u32 len; | u32 len; | ||||
Deserialize_int_4(buffer, len); | Deserialize_int_4(buffer, len); | ||||
if (buffer + len > bufferend) | if (buffer + len > bufferend) | ||||
return NULL; | return NULL; | ||||
*this = std::string(buffer, buffer + len); | *this = std::string(buffer, buffer + len); | ||||
return buffer + len; | return buffer + len; | ||||
} | } | ||||
Show All 17 Lines |
Wildfire Games · Phabricator