QMTranslatorImpl.cpp revision a9a79301a7d78abffc51521473bbb5a1e08028c5
/* $Id$ */
/** @file
* VirtualBox API translation handling class
*/
/*
* Copyright (C) 2014 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
#include <vector>
#include <set>
#include <algorithm>
#include <iterator>
#include <QMTranslator.h>
/* QM File Magic Number */
0x3c, 0xb8, 0x64, 0x18, 0xca, 0xef, 0x9c, 0x95,
0xcd, 0x21, 0x1c, 0xbf, 0x60, 0xa1, 0xbd, 0xdd
};
/* Used internally */
{
const char *m_str;
public:
};
/* Bytes stream. Used by the parser to iterate through the data */
class QMBytesStream
{
const uint8_t * const m_dataStart;
/* Function stub for transform method */
{
return RT_BE2H_U16(value);
}
public:
{
setEnd();
}
/* Sets end pointer
* Used in message reader to detect the end of message block */
{
}
{
checkSize(1);
return *m_iter++;
}
{
checkSize(4);
m_iter += 4;
return RT_BE2H_U32(result);
}
/* Reads string in UTF16 and converts it into a UTF8 string */
{
/* We cannot convert to host endianess without copying the data
* since the file might be mapped to the memory and any memory
* change will lead to the change of the file. */
}
/* Reads string in one-byte encoding
* The string is assumed to be in ISO-8859-1 encoding */
{
return result;
}
/* Checks the magic number
* Should be called when in the beginning of the data */
inline void checkMagic()
{
m_iter += MagicLength;
}
/* Has we reached the end pointer? */
/* Returns current stream position */
/* Moves current pointer to a desired position */
/* Checks whether stream has enough data to read size bytes */
{
}
};
/* Internal QMTranslator implementation */
class QMTranslator_Impl
{
struct QMMessage
{
/* Everything is in UTF-8 */
};
struct HashOffset
{
bool operator<(const HashOffset &obj) const
{
}
};
public:
QMTranslator_Impl() {}
const char *translate(const char *pszContext,
const char *pszSource,
const char *pszDisamb) const
{
do {
{
break;
}
/* Try without disambiguating comment if it isn't empty */
if (pszDisamb)
{
else pszDisamb = "";
}
}
{
/* Load into local variables. If we failed during the load,
* it would allow us to keep the object in a valid (previous) state. */
stream.checkMagic();
while (!stream.hasFinished())
{
/* Hashes and Context sections are ignored. They contain hash tables
* to speed-up search which is not useful since we recalculate all hashes
* and don't perform context search by hash */
switch (sectionCode)
{
case Messages:
break;
case Hashes:
/* Only get size information to speed-up vector filling
* if Hashes section goes in the file before Message section */
/* NB! NO BREAK HERE */
case Context:
break;
default:
throw QMException("Unkown section");
}
}
/* Store the data into member variables.
* The following functions never generate exceptions */
}
private:
/* Some QM stuff */
enum SectionType
{
Hashes = 0x42,
Messages = 0x69,
Contexts = 0x2f
};
enum MessageType
{
End = 1,
SourceText16 = 2,
Translation = 3,
Context16 = 4,
Hash = 5,
SourceText = 6,
Context = 7,
Comment = 8
};
/* Read messages from the stream. */
static void parseMessages(QMBytesStream &stream, QMHashSet * const hashSet, QMMessageArray * const messageArray, size_t cbSize)
{
while (!stream.hasFinished())
{
}
}
/* Parse one message from the stream */
{
while(!stream.hasFinished())
{
switch(type)
{
case End:
return;
/* Ignored as obsolete */
case Context16:
case SourceText16:
break;
case Translation:
{
break;
}
case Hash:
break;
case SourceText:
{
break;
}
case Context:
{
break;
}
case Comment:
{
break;
}
default:
/* Ignore unknown block */
break;
}
}
}
/* Defines the so called `hashpjw' function by P.J. Weinberger
1986, 1987 Bell Telephone Laboratories, Inc.] */
{
{
if ((g = hash & 0xf0000000ul) != 0)
{
hash ^= g >> 24;
hash ^= g;
}
}
}
};
/* Inteface functions implementation */
const char *QMTranslator::translate(const char *pszContext, const char *pszSource, const char *pszDisamb) const throw()
{
}
/* The function is noexcept for now but it may be changed
* to throw exceptions if required to catch them in another
* place. */
{
/* To free safely the file in case of exception */
struct FileLoader
{
int rc;
FileLoader(const char *pszFname)
{
}
~FileLoader()
{
if (isSuccess())
}
};
try
{
{
}
}
{
return VERR_INTERNAL_ERROR;
}
catch(...)
{
return VERR_GENERAL_FAILURE;
}
}