mirror of
https://github.com/SWG-Source/src.git
synced 2026-07-28 22:15:49 -04:00
Added unicodeArchive library
This commit is contained in:
Vendored
+1
@@ -3,3 +3,4 @@ add_subdirectory(archive)
|
||||
add_subdirectory(fileInterface)
|
||||
add_subdirectory(localization)
|
||||
add_subdirectory(unicode)
|
||||
add_subdirectory(unicodeArchive)
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
|
||||
project(unicodeArchive)
|
||||
|
||||
if(WIN32)
|
||||
add_definitions(/D_CRT_SECURE_NO_WARNINGS)
|
||||
endif()
|
||||
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/public)
|
||||
|
||||
add_subdirectory(src)
|
||||
+1
@@ -0,0 +1 @@
|
||||
#include "../../src/shared/FirstUnicodeArchive.h"
|
||||
+1
@@ -0,0 +1 @@
|
||||
#include "../../src/shared/UnicodeArchive.h"
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
#include "../../src/shared/UnicodeAutoDeltaPackedMap.h"
|
||||
@@ -0,0 +1,30 @@
|
||||
|
||||
|
||||
set(SHARED_SOURCES
|
||||
shared/FirstUnicodeArchive.h
|
||||
shared/UnicodeArchive.cpp
|
||||
shared/UnicodeArchive.h
|
||||
shared/UnicodeAutoDeltaPackedMap.cpp
|
||||
shared/UnicodeAutoDeltaPackedMap.h
|
||||
)
|
||||
|
||||
if(WIN32)
|
||||
set(PLATFORM_SOURCES
|
||||
win32/FirstUnicodeArchive.cpp
|
||||
)
|
||||
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/win32)
|
||||
else()
|
||||
set(PLATFORM_SOURCES "")
|
||||
endif()
|
||||
|
||||
include_directories(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shared
|
||||
${SWG_EXTERNALS_SOURCE_DIR}/ours/library/archive/include
|
||||
${SWG_EXTERNALS_SOURCE_DIR}/ours/library/unicode/include
|
||||
)
|
||||
|
||||
add_library(unicodeArchive
|
||||
${SHARED_SOURCES}
|
||||
${PLATFORM_SOURCES}
|
||||
)
|
||||
@@ -0,0 +1,20 @@
|
||||
// ======================================================================
|
||||
//
|
||||
// FirstUnicodeArchive.h
|
||||
// Copyright 2002, Sony Online Entertainment Inc.
|
||||
// All Rights Reserved.
|
||||
//
|
||||
// ======================================================================
|
||||
|
||||
#ifndef INCLUDED_FirstUnicodeArchive_H
|
||||
#define INCLUDED_FirstUnicodeArchive_H
|
||||
|
||||
// ======================================================================
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma warning(disable: 4702)
|
||||
#endif
|
||||
|
||||
// ======================================================================
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,42 @@
|
||||
//======================================================================
|
||||
//
|
||||
// UnicodeArchive.cpp
|
||||
// copyright (c) 2002 Sony Online Entertainment
|
||||
//
|
||||
//======================================================================
|
||||
|
||||
#include "unicodeArchive/FirstUnicodeArchive.h"
|
||||
#include "unicodeArchive/UnicodeArchive.h"
|
||||
|
||||
#include "Archive/Archive.h"
|
||||
|
||||
//======================================================================
|
||||
|
||||
namespace Archive
|
||||
{
|
||||
//-----------------------------------------------------------------------
|
||||
void get(ReadIterator & source, Unicode::String & target)
|
||||
{
|
||||
unsigned int size = 0;
|
||||
Archive::get (source, size);
|
||||
|
||||
const unsigned char * const buf = source.getBuffer();
|
||||
const Unicode::unicode_char_t * const ubuf = reinterpret_cast<const Unicode::unicode_char_t *>(buf);
|
||||
|
||||
target.assign (ubuf, ubuf + size);
|
||||
|
||||
const unsigned int readSize = size * sizeof (Unicode::unicode_char_t);
|
||||
source.advance(readSize);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void put(ByteStream & target, const Unicode::String & source)
|
||||
{
|
||||
const unsigned int size = source.size ();
|
||||
Archive::put (target, size);
|
||||
target.put (source.data(), size * sizeof (Unicode::unicode_char_t));
|
||||
}
|
||||
}
|
||||
|
||||
//======================================================================
|
||||
@@ -0,0 +1,26 @@
|
||||
// UnicodeArchive.h
|
||||
// copyright 2001 Verant Interactive
|
||||
// Author: Justin Randall
|
||||
|
||||
#ifndef _INCLUDED_UnicodeArchive_H
|
||||
#define _INCLUDED_UnicodeArchive_H
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
#include "Unicode.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
namespace Archive
|
||||
{
|
||||
class ReadIterator;
|
||||
class ByteStream;
|
||||
|
||||
void get(ReadIterator & source, Unicode::String & target);
|
||||
void put(ByteStream & target, const Unicode::String & source);
|
||||
|
||||
}// namespace Archive
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
#endif // _INCLUDED_UnicodeArchive_H
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
// ======================================================================
|
||||
//
|
||||
// UnicodeAutoDeltaPackedMap.cpp
|
||||
// copyright (c) 2004 Sony Online Entertainment
|
||||
//
|
||||
// ======================================================================
|
||||
|
||||
#include "unicodeArchive/FirstUnicodeArchive.h"
|
||||
#include "unicodeArchive/UnicodeAutoDeltaPackedMap.h"
|
||||
|
||||
#include "UnicodeUtils.h"
|
||||
#include "unicodeArchive/UnicodeArchive.h"
|
||||
#include <stdio.h>
|
||||
|
||||
// ======================================================================
|
||||
|
||||
namespace Archive
|
||||
{
|
||||
template <> void AutoDeltaPackedMap<int, Unicode::String>::pack(ByteStream & target, const std::string & buffer)
|
||||
{
|
||||
char temp[200];
|
||||
char valueBuffer[200];
|
||||
Command c;
|
||||
|
||||
Archive::put(target, countCharacter(buffer,':'));
|
||||
Archive::put(target, static_cast<size_t>(0)); // baselineCommandCount
|
||||
|
||||
int tempPos = 0;
|
||||
for (std::string::const_iterator i=buffer.begin(); i!=buffer.end(); ++i)
|
||||
{
|
||||
if (*i==':')
|
||||
{
|
||||
temp[tempPos]='\0';
|
||||
valueBuffer[0]='\0';
|
||||
sscanf(temp,"%i",&c.key);
|
||||
char const * const valueStart = strchr(temp,' ');
|
||||
if (valueStart)
|
||||
c.value = Unicode::utf8ToWide(valueStart+1);
|
||||
else
|
||||
c.value = Unicode::String();
|
||||
Archive::put(target, static_cast<unsigned char>(Command::ADD));
|
||||
Archive::put(target, c.key);
|
||||
Archive::put(target, c.value);
|
||||
tempPos=0;
|
||||
}
|
||||
else
|
||||
{
|
||||
temp[tempPos++]=*i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ======================================================================
|
||||
|
||||
template <> void AutoDeltaPackedMap<int, Unicode::String>::unpack(ReadIterator & source, std::string & buffer)
|
||||
{
|
||||
char temp[200];
|
||||
|
||||
Command c;
|
||||
size_t commandCount;
|
||||
size_t baselineCommandCount;
|
||||
|
||||
Archive::get(source, commandCount);
|
||||
Archive::get(source, baselineCommandCount);
|
||||
|
||||
if (commandCount==0)
|
||||
{
|
||||
buffer=' '; // An empty map is represented as a single space, because a completely empty string is used to mean "no change"
|
||||
}
|
||||
else
|
||||
{
|
||||
for (size_t i = 0; i < commandCount; ++i)
|
||||
{
|
||||
Archive::get(source, c.cmd);
|
||||
assert(c.cmd == Command::ADD); // only add is valid in unpack
|
||||
Archive::get(source, c.key);
|
||||
Archive::get(source, c.value);
|
||||
|
||||
#ifdef WIN32
|
||||
_snprintf(temp, sizeof(temp)-1, "%i %s:", c.key, Unicode::wideToUTF8(c.value).c_str());
|
||||
#else
|
||||
snprintf(temp, sizeof(temp)-1, "%i %s:", c.key, Unicode::wideToUTF8(c.value).c_str());
|
||||
#endif
|
||||
|
||||
temp[sizeof(temp)-1]='\0';
|
||||
buffer+=temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ======================================================================
|
||||
@@ -0,0 +1,26 @@
|
||||
// ======================================================================
|
||||
//
|
||||
// UnicodeAutoDeltaPackedMap.h
|
||||
// copyright (c) 2004 Sony Online Entertainment
|
||||
//
|
||||
// ======================================================================
|
||||
|
||||
#ifndef INCLUDED_UnicodeAutoDeltaPackedMap_H
|
||||
#define INCLUDED_UnicodeAutoDeltaPackedMap_H
|
||||
|
||||
// ======================================================================
|
||||
|
||||
#include "Archive/AutoDeltaPackedMap.h"
|
||||
#include "Unicode.h"
|
||||
|
||||
// ======================================================================
|
||||
|
||||
namespace Archive
|
||||
{
|
||||
template <> void AutoDeltaPackedMap<int, Unicode::String>::pack(ByteStream & target, const std::string & buffer);
|
||||
template <> void AutoDeltaPackedMap<int, Unicode::String>::unpack(ReadIterator & source, std::string & buffer);
|
||||
}
|
||||
|
||||
// ======================================================================
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,12 @@
|
||||
//======================================================================
|
||||
//
|
||||
// FirstUnicodeArchive.cpp
|
||||
// copyright (c) 2002 Sony Online Entertainment
|
||||
//
|
||||
//======================================================================
|
||||
|
||||
#include "unicodeArchive/FirstUnicodeArchive.h"
|
||||
|
||||
//======================================================================
|
||||
|
||||
//======================================================================
|
||||
Reference in New Issue
Block a user