added seek directive to fixed-length string reads

This commit is contained in:
Jack Andersen 2015-06-19 10:40:59 -10:00
parent 3dfb001f3d
commit e641dbbe4b
4 changed files with 47 additions and 43 deletions

View File

@ -1,7 +1,7 @@
# PKGBUILD for libAthena # PKGBUILD for libAthena
_pkgname=libathena _pkgname=libathena
pkgname=$_pkgname-git pkgname=$_pkgname-git
pkgver=1.1.0.35.gfd3db3e pkgver=1.1.0.37.g3dfb001
pkgrel=1 pkgrel=1
pkgdesc="Basic cross platform IO library" pkgdesc="Basic cross platform IO library"
arch=('i686' 'x86_64') arch=('i686' 'x86_64')

View File

@ -1,7 +1,7 @@
# PKGBUILD for atdna # PKGBUILD for atdna
_pkgname=atdna _pkgname=atdna
pkgname=$_pkgname-git pkgname=$_pkgname-git
pkgver=1.1.0.36.g242a069 pkgver=1.1.0.37.g3dfb001
pkgrel=1 pkgrel=1
pkgdesc="Companion DNA utility for libAthena" pkgdesc="Companion DNA utility for libAthena"
arch=('i686' 'x86_64') arch=('i686' 'x86_64')

View File

@ -340,71 +340,72 @@ atVec4f FileReader::readVec4f()
return val; return val;
} }
std::string FileReader::readString(atInt32 maxlen) std::string FileReader::readString(atInt32 fixedLen)
{ {
std::string ret; std::string ret;
atUint8 chr = readByte(); atUint8 chr = readByte();
atInt32 i;
atInt32 i = 0; for (i = 0 ; chr != 0 ; ++i)
while (chr != 0)
{ {
if (maxlen >= 0 && i >= maxlen - 1) if (fixedLen >= 0 && i >= fixedLen - 1)
break; break;
ret += chr; ret += chr;
chr = readByte(); chr = readByte();
i++;
} }
if (fixedLen >= 0 && i < fixedLen)
seek(fixedLen - i);
return ret; return ret;
} }
std::wstring FileReader::readWString(atInt32 maxlen) std::wstring FileReader::readWString(atInt32 fixedLen)
{ {
std::wstring ret; std::wstring ret;
atUint16 chr = readUint16(); atUint16 chr = readUint16();
atInt32 i = 0; atInt32 i;
for (i = 0 ; chr != 0 ; ++i)
while (chr != 0)
{ {
if (maxlen >= 0 && i >= maxlen - 1) if (fixedLen >= 0 && i >= fixedLen - 1)
break; break;
ret += chr; ret += chr;
chr = readUint16(); chr = readUint16();
i++;
} }
if (fixedLen >= 0 && i < fixedLen)
seek(fixedLen - i);
return ret; return ret;
} }
std::string FileReader::readUnicode(atInt32 maxlen) std::string FileReader::readUnicode(atInt32 fixedLen)
{ {
if (!isOpen()) if (!isOpen())
THROW_INVALID_OPERATION_EXCEPTION_RETURN(std::string(), "File not open for reading"); THROW_INVALID_OPERATION_EXCEPTION_RETURN(std::string(), "File not open for reading");
std::string ret; std::string ret;
std::vector<short> tmp; std::vector<atUint16> tmp;
atInt32 i;
atInt32 i = 0; for (i = 0 ;; ++i)
for (;;)
{ {
if (maxlen >= 0 && i >= maxlen - 1) if (fixedLen >= 0 && i >= fixedLen - 1)
break; break;
short chr = readUint16(); atUint16 chr = readUint16();
if (chr) if (chr)
tmp.push_back(chr); tmp.push_back(chr);
else else
break; break;
i++;
}; };
if (fixedLen >= 0 && i < fixedLen)
seek(fixedLen - i);
utf8::utf16to8(tmp.begin(), tmp.end(), back_inserter(ret)); utf8::utf16to8(tmp.begin(), tmp.end(), back_inserter(ret));
return ret; return ret;

View File

@ -493,7 +493,7 @@ atVec4f MemoryReader::readVec4f()
return result; return result;
} }
std::string MemoryReader::readUnicode(atInt32 maxlen) std::string MemoryReader::readUnicode(atInt32 fixedLen)
{ {
if (!m_data) if (!m_data)
loadData(); loadData();
@ -502,11 +502,10 @@ std::string MemoryReader::readUnicode(atInt32 maxlen)
std::vector<short> tmp; std::vector<short> tmp;
atUint16 chr = readUint16(); atUint16 chr = readUint16();
atInt32 i = 0; atInt32 i;
for (i = 0 ;; ++i)
for (;;)
{ {
if (maxlen >= 0 && i >= maxlen - 1) if (fixedLen >= 0 && i >= fixedLen - 1)
break; break;
if (!chr) if (!chr)
@ -514,50 +513,54 @@ std::string MemoryReader::readUnicode(atInt32 maxlen)
tmp.push_back(chr); tmp.push_back(chr);
chr = readUint16(); chr = readUint16();
i++;
} }
if (fixedLen >= 0 && i < fixedLen)
seek(fixedLen - i);
utf8::utf16to8(tmp.begin(), tmp.end(), back_inserter(ret)); utf8::utf16to8(tmp.begin(), tmp.end(), back_inserter(ret));
return ret; return ret;
} }
std::string MemoryReader::readString(atInt32 maxlen) std::string MemoryReader::readString(atInt32 fixedLen)
{ {
std::string ret; std::string ret;
atUint8 chr = readByte(); atUint8 chr = readByte();
atInt32 i = 0; atInt32 i;
for (i = 0 ; chr != 0 ; ++i)
while (chr != 0)
{ {
if (maxlen >= 0 && i >= maxlen - 1) if (fixedLen >= 0 && i >= fixedLen - 1)
break; break;
ret += chr; ret += chr;
chr = readByte(); chr = readByte();
i++;
} }
if (fixedLen >= 0 && i < fixedLen)
seek(fixedLen - i);
return ret; return ret;
} }
std::wstring MemoryReader::readWString(atInt32 maxlen) std::wstring MemoryReader::readWString(atInt32 fixedLen)
{ {
std::wstring ret; std::wstring ret;
atUint16 chr = readUint16(); atUint16 chr = readUint16();
atInt32 i = 0; atInt32 i;
for (i = 0 ; chr != 0 ; ++i)
while (chr != 0)
{ {
if (maxlen >= 0 && i >= maxlen - 1) if (fixedLen >= 0 && i >= fixedLen - 1)
break; break;
ret += chr; ret += chr;
chr = readUint16(); chr = readUint16();
i++;
} }
if (fixedLen >= 0 && i < fixedLen)
seek(fixedLen - i);
return ret; return ret;
} }