Skip to content

Commit

Permalink
Updated to version 79b7bde of tinygettext
Browse files Browse the repository at this point in the history
  • Loading branch information
Grumbel committed Aug 3, 2014
1 parent af57bbb commit 564f07b
Show file tree
Hide file tree
Showing 23 changed files with 106 additions and 74 deletions.
12 changes: 12 additions & 0 deletions external/tinygettext/.gitignore
@@ -0,0 +1,12 @@
*.o
*~
/.sconsign.dblite
/CMakeCache.txt
/CMakeFiles/
/Makefile
/cmake_install.cmake
/libtinygettext.so
/src/libtinygettext.a
/test/po_parser_test
/test/tinygettext_test
/tinygettext.pc
24 changes: 13 additions & 11 deletions external/tinygettext/CMakeLists.txt
Expand Up @@ -6,12 +6,12 @@
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Expand Down Expand Up @@ -92,22 +92,22 @@ ENDIF(HAVE_ICONV_CONST)

## build list of source files

FILE(GLOB TINYGETTEXT_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} tinygettext/*.cpp)
FILE(GLOB TINYGETTEXT_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} tinygettext/*.hpp)
FILE(GLOB TINYGETTEXT_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} src/*.cpp)
FILE(GLOB TINYGETTEXT_HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} include/tinygettext/*.hpp)

## define a target for building the library

ADD_LIBRARY(tinygettext ${TINYGETTEXT_SOURCES})

## Add tinygettext dir to search path

INCLUDE_DIRECTORIES(${tinygettext_SOURCE_DIR})
INCLUDE_DIRECTORIES(include/)

## Debug options

OPTION(WERROR "Stops on first compiler warning in debug mode" OFF)
IF(CMAKE_COMPILER_IS_GNUCC)
ADD_DEFINITIONS(-O3 -Wall -Wextra -Weffc++ -pedantic)
ADD_DEFINITIONS(-std=c++0x -O3 -Wall -Wextra -Weffc++ -pedantic)
# -ansi fails in MinGW
OPTION(WARNINGS "Enable long list of warnings for compiler to check" ON)
IF(WARNINGS)
Expand All @@ -119,12 +119,12 @@ IF(CMAKE_COMPILER_IS_GNUCC)
-Wsign-promo -Wswitch-enum
-Wcast-align -Wcast-qual
-Wdisabled-optimization
-Wfloat-equal
-Wfloat-equal
-Wformat=2
-Winit-self
-Winit-self
-Winvalid-pch -Wunsafe-loop-optimizations
-Wlogical-op
-Wmissing-format-attribute -Wmissing-include-dirs -Wmissing-noreturn
-Wlogical-op
-Wmissing-format-attribute -Wmissing-include-dirs -Wmissing-noreturn
-Wpacked
-Wredundant-decls
-Wshadow
Expand All @@ -143,7 +143,7 @@ ENDIF(CMAKE_COMPILER_IS_GNUCC)

## Extra definitions

ADD_DEFINITIONS(-DVERSION=\\\"${VERSION}\\\")
ADD_DEFINITIONS(-DVERSION=${VERSION})

## Generate test executables in the right place

Expand Down Expand Up @@ -175,3 +175,5 @@ INSTALL(FILES ${TINYGETTEXT_HEADERS}
DESTINATION include/tinygettext)
INSTALL(FILES ${tinygettext_BINARY_DIR}/tinygettext.pc
DESTINATION ${LIB_SUBDIR}/pkgconfig)

# EOF #
32 changes: 19 additions & 13 deletions external/tinygettext/SConstruct
@@ -1,8 +1,14 @@
# -*- python -*-

env = Environment(CXXFLAGS=['-O0',
import os

env = Environment(ENV=os.environ,
CXX="g++",
CXXFLAGS=['-O0',
'-g3',
'-std=c++0x',
'-Wall',
'-Wextra',
'-Wcast-qual',
'-Wconversion',
'-Weffc++',
Expand All @@ -12,24 +18,24 @@ env = Environment(CXXFLAGS=['-O0',
'-Wno-unused-parameter',
'-Wnon-virtual-dtor',
'-Wshadow',
'-ansi',
# '-ansi', # conflicts with -std=c++0x
'-pedantic',
],
CPPPATH=['tinygettext', '.'])
CPPPATH=['include', 'src'])

# env.ParseConfig("sdl-config --cflags --libs")
# env['CPPDEFINES'] += HAVE_SDL

libtinygettext = env.StaticLibrary('tinygettext/tinygettext',
['tinygettext/tinygettext.cpp',
'tinygettext/language.cpp',
'tinygettext/plural_forms.cpp',
'tinygettext/dictionary.cpp',
'tinygettext/dictionary_manager.cpp',
'tinygettext/unix_file_system.cpp',
'tinygettext/po_parser.cpp',
'tinygettext/iconv.cpp',
'tinygettext/log.cpp'])
libtinygettext = env.StaticLibrary('src/tinygettext',
['src/tinygettext.cpp',
'src/language.cpp',
'src/plural_forms.cpp',
'src/dictionary.cpp',
'src/dictionary_manager.cpp',
'src/unix_file_system.cpp',
'src/po_parser.cpp',
'src/iconv.cpp',
'src/log.cpp'])

env.Program('test/tinygettext_test', ['test/tinygettext_test.cpp', libtinygettext])
env.Program('test/po_parser_test', ['test/po_parser_test.cpp', libtinygettext])
Expand Down
Expand Up @@ -18,9 +18,10 @@
#ifndef HEADER_TINYGETTEXT_DICTIONARY_HPP
#define HEADER_TINYGETTEXT_DICTIONARY_HPP

#include <map>
#include <vector>
#include <string>
#include <unordered_map>
#include <vector>

#include "plural_forms.hpp"

namespace tinygettext {
Expand All @@ -31,10 +32,10 @@ namespace tinygettext {
class Dictionary
{
private:
typedef std::map<std::string, std::vector<std::string> > Entries;
typedef std::unordered_map<std::string, std::vector<std::string> > Entries;
Entries entries;

typedef std::map<std::string, Entries> CtxtEntries;
typedef std::unordered_map<std::string, Entries> CtxtEntries;
CtxtEntries ctxt_entries;

std::string charset;
Expand Down
Expand Up @@ -18,11 +18,11 @@
#ifndef HEADER_TINYGETTEXT_DICTIONARY_MANAGER_HPP
#define HEADER_TINYGETTEXT_DICTIONARY_MANAGER_HPP

#include <map>
#include <memory>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
#include <memory>

#include "dictionary.hpp"
#include "language.hpp"
Expand All @@ -37,7 +37,7 @@ class FileSystem;
class DictionaryManager
{
private:
typedef std::map<Language, Dictionary*> Dictionaries;
typedef std::unordered_map<Language, Dictionary*, Language_hash> Dictionaries;
Dictionaries dictionaries;

typedef std::vector<std::string> SearchPath;
Expand All @@ -51,7 +51,7 @@ class DictionaryManager

Dictionary empty_dict;

std::auto_ptr<FileSystem> filesystem;
std::unique_ptr<FileSystem> filesystem;

void clear_cache();

Expand Down Expand Up @@ -85,7 +85,7 @@ class DictionaryManager
/** Return a set of the available languages in their country code */
std::set<Language> get_languages();

void set_filesystem(std::auto_ptr<FileSystem> filesystem);
void set_filesystem(std::unique_ptr<FileSystem> filesystem);

private:
DictionaryManager (const DictionaryManager&);
Expand Down
Expand Up @@ -30,8 +30,8 @@ class FileSystem
public:
virtual ~FileSystem() {}

virtual std::vector<std::string> open_directory(const std::string& pathname) =0;
virtual std::auto_ptr<std::istream> open_file(const std::string& filename) =0;
virtual std::vector<std::string> open_directory(const std::string& pathname) =0;
virtual std::unique_ptr<std::istream> open_file(const std::string& filename) =0;
};

} // namespace tinygettext
Expand Down
File renamed without changes.
Expand Up @@ -19,6 +19,7 @@
#define HEADER_TINYGETTEXT_LANGUAGE_HPP

#include <string>
#include <unordered_map>

namespace tinygettext {

Expand Down Expand Up @@ -74,16 +75,25 @@ class Language
variable: {language}_{country}@{modifier} */
std::string str() const;

bool operator==(const Language& rhs);
bool operator!=(const Language& rhs);
bool operator==(const Language& rhs) const;
bool operator!=(const Language& rhs) const;

friend bool operator<(const Language& lhs, const Language& rhs);
friend struct Language_hash;
};

inline bool operator<(const Language& lhs, const Language& rhs) {
return lhs.language_spec < rhs.language_spec;
}

struct Language_hash
{
size_t operator()(const Language& v) const
{
return reinterpret_cast<size_t>(v.language_spec);
}
};

} // namespace tinygettext

#endif
Expand Down
File renamed without changes.
Expand Up @@ -50,7 +50,7 @@ class POParser
void parse();
void next_line();
std::string get_string(unsigned int skip);
void get_string_line(std::ostringstream& str,unsigned int skip);
void get_string_line(std::ostringstream& str, size_t skip);
bool is_empty_line();
bool prefix(const char* );
void error(const std::string& msg) __attribute__((__noreturn__));
Expand Down
Expand Up @@ -28,7 +28,7 @@ class UnixFileSystem : public FileSystem
UnixFileSystem();

std::vector<std::string> open_directory(const std::string& pathname);
std::auto_ptr<std::istream> open_file(const std::string& filename);
std::unique_ptr<std::istream> open_file(const std::string& filename);
};

} // namespace tinygettext
Expand Down
Expand Up @@ -16,8 +16,9 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

#include <assert.h>
#include "log_stream.hpp"
#include "dictionary.hpp"

#include "tinygettext/log_stream.hpp"
#include "tinygettext/dictionary.hpp"

namespace tinygettext {

Expand Down
Expand Up @@ -15,7 +15,7 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

#include "dictionary_manager.hpp"
#include "tinygettext/dictionary_manager.hpp"

#include <memory>
#include <assert.h>
Expand All @@ -24,9 +24,9 @@
#include <fstream>
#include <algorithm>

#include "log_stream.hpp"
#include "po_parser.hpp"
#include "unix_file_system.hpp"
#include "tinygettext/log_stream.hpp"
#include "tinygettext/po_parser.hpp"
#include "tinygettext/unix_file_system.hpp"

namespace tinygettext {

Expand Down Expand Up @@ -146,7 +146,7 @@ DictionaryManager::get_dictionary(const Language& language)
std::string pofile = *p + "/" + best_filename;
try
{
std::auto_ptr<std::istream> in = filesystem->open_file(pofile);
std::unique_ptr<std::istream> in = filesystem->open_file(pofile);
if (!in.get())
{
log_error << "error: failure opening: " << pofile << std::endl;
Expand Down Expand Up @@ -232,9 +232,9 @@ DictionaryManager::add_directory(const std::string& pathname)
}

void
DictionaryManager::set_filesystem(std::auto_ptr<FileSystem> filesystem_)
DictionaryManager::set_filesystem(std::unique_ptr<FileSystem> filesystem_)
{
filesystem = filesystem_;
filesystem = std::move(filesystem_);
}

} // namespace tinygettext
Expand Down
Expand Up @@ -23,8 +23,8 @@
#include <string.h>
#include <stdlib.h>

#include "iconv.hpp"
#include "log_stream.hpp"
#include "tinygettext/iconv.hpp"
#include "tinygettext/log_stream.hpp"

namespace tinygettext {

Expand Down
Expand Up @@ -15,10 +15,10 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

#include "language.hpp"
#include "tinygettext/language.hpp"

#include <map>
#include <assert.h>
#include <unordered_map>
#include <vector>

namespace tinygettext {
Expand Down Expand Up @@ -285,7 +285,7 @@ LanguageSpec languages[] = {
std::string
resolve_language_alias(const std::string& name)
{
typedef std::map<std::string, std::string> Aliases;
typedef std::unordered_map<std::string, std::string> Aliases;
static Aliases language_aliases;
if (language_aliases.empty())
{
Expand Down Expand Up @@ -363,15 +363,15 @@ resolve_language_alias(const std::string& name)
Language
Language::from_spec(const std::string& language, const std::string& country, const std::string& modifier)
{
static std::map<std::string, std::vector<LanguageSpec*> > language_map;
static std::unordered_map<std::string, std::vector<LanguageSpec*> > language_map;

if (language_map.empty())
{ // Init language_map
for(int i = 0; languages[i].language != NULL; ++i)
language_map[languages[i].language].push_back(&languages[i]);
}

std::map<std::string, std::vector<LanguageSpec*> >::iterator i = language_map.find(language);
std::unordered_map<std::string, std::vector<LanguageSpec*> >::iterator i = language_map.find(language);
if (i != language_map.end())
{
std::vector<LanguageSpec*>& lst = i->second;
Expand Down Expand Up @@ -553,13 +553,13 @@ Language::str() const
}

bool
Language::operator==(const Language& rhs)
Language::operator==(const Language& rhs) const
{
return language_spec == rhs.language_spec;
}

bool
Language::operator!=(const Language& rhs)
Language::operator!=(const Language& rhs) const
{
return language_spec != rhs.language_spec;
}
Expand Down

0 comments on commit 564f07b

Please sign in to comment.