Skip to content

Commit

Permalink
Merge pull request #369 from afh/pull/utfcpp_subtree
Browse files Browse the repository at this point in the history
Replace utfcpp submodule with partial subtree
  • Loading branch information
jwiegley committed Aug 4, 2015
2 parents 614ba7d + 967a761 commit 947a46e
Show file tree
Hide file tree
Showing 13 changed files with 1,039 additions and 16 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
@@ -1,3 +0,0 @@
[submodule "lib/utfcpp"]
path = lib/utfcpp
url = http://github.com/ledger/utfcpp.git
16 changes: 13 additions & 3 deletions CMakeLists.txt
Expand Up @@ -12,6 +12,9 @@ set(Ledger_VERSION_PATCH 1)
set(Ledger_VERSION_PRERELEASE "-alpha.1")
set(Ledger_VERSION_DATE 20141005)

# Point CMake at any custom modules we may ship
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")

enable_testing()

add_definitions(-std=c++11)
Expand Down Expand Up @@ -244,13 +247,20 @@ endmacro(add_ledger_library_dependencies _target)

########################################################################

include(FindUtfcpp)
if (UTFCPP_FOUND)
include_directories("${UTFCPP_INCLUDE_DIR}")
else()
message(FATAL_ERROR "Missing required header file: utf8.h\n"
"Define UTFCPP_PATH or install utfcpp locally into the source tree below lib/utfcpp/."
)
endif()

set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})

# add the binary tree to the search path for include files so that we will
# find TutorialConfig.h
include_directories("${PROJECT_SOURCE_DIR}/lib")
include_directories("${PROJECT_SOURCE_DIR}/lib/utfcpp/source")
# find system.hh
include_directories("${PROJECT_BINARY_DIR}")

configure_file(
Expand Down
10 changes: 2 additions & 8 deletions acprep
Expand Up @@ -490,17 +490,10 @@ class PrepareBuild(CommandLineApp):
# Update local files with the latest information #
#########################################################################

def phase_submodule(self, *args):
self.log.info('Executing phase: submodule')
if self.git_working_tree():
self.execute('git', 'submodule', 'init')
self.execute('git', 'submodule', 'update')

def phase_pull(self, *args):
self.log.info('Executing phase: pull')
if self.git_working_tree():
self.execute('git', 'pull')
self.phase_submodule()

#########################################################################
# Automatic installation of build dependencies #
Expand Down Expand Up @@ -569,6 +562,7 @@ class PrepareBuild(CommandLineApp):
'libedit-dev',
'texinfo',
'lcov',
'libutfcpp-dev',
'sloccount'
] + BoostInfo().dependencies('ubuntu-trusty')
elif re.search('saucy', info):
Expand Down Expand Up @@ -606,6 +600,7 @@ class PrepareBuild(CommandLineApp):
'libedit-dev',
'texinfo',
'lcov',
'libutfcpp-dev',
'sloccount'
] + BoostInfo().dependencies('ubuntu-precise')
else:
Expand Down Expand Up @@ -885,7 +880,6 @@ class PrepareBuild(CommandLineApp):

def phase_config(self, *args):
self.log.info('Executing phase: config')
self.phase_submodule()
self.phase_configure(*args)
if self.should_clean:
self.phase_clean()
Expand Down
30 changes: 30 additions & 0 deletions cmake/FindUtfcpp.cmake
@@ -0,0 +1,30 @@
# - Try to find utfcpp
# Once done, this will define
#
# UTFCPP_FOUND - system has utfcpp's utf8.h
# UTFCPP_PATH - the utfcpp include directories

include(CheckCXXSourceCompiles)

set(UTFCPP_FOUND FALSE)

find_path(UTFCPP_INCLUDE_DIR
NAMES utf8.h
HINTS "${UTFCPP_PATH}" "${PROJECT_SOURCE_DIR}/lib/utfcpp/v2_0/source"
)

if (UTFCPP_INCLUDE_DIR)
set(CMAKE_REQUIRED_INCLUDES "${UTFCPP_INCLUDE_DIR}")
set(UTFCPP_FOUND TRUE)
endif()

check_cxx_source_compiles("
#include <string>
#include \"utf8.h\"
int main(int argc, char** argv) {
std::string input = std::string(\"utfcpp\");
const char * p = input.c_str();
std::size_t len = input.length();
utf8::is_valid(p, p + len);
}" HAVE_WORKING_UTFCPP)
1 change: 0 additions & 1 deletion lib/utfcpp
Submodule utfcpp deleted from 2233ec
2 changes: 1 addition & 1 deletion doc/LICENSE-utfcpp → lib/utfcpp/v2_0/LICENSE
@@ -1,4 +1,4 @@
Copyright 2006 Nemanja Trifunovic
Boost Software License - Version 1.0 - August 17th, 2003

Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
Expand Down
18 changes: 18 additions & 0 deletions lib/utfcpp/v2_0/buildrelease.pl
@@ -0,0 +1,18 @@
#! /usr/bin/perl

$release_files = 'source/utf8.h source/utf8/core.h source/utf8/checked.h source/utf8/unchecked.h doc/utf8cpp.html doc/ReleaseNotes';

# First get the latest version
`svn update`;

# Then construct the name of the zip file
$argc = @ARGV;
if ($argc > 0) {
$zip_name = $ARGV[0];
}
else {
$zip_name = "utf8";
}

# Zip the files to an archive
`zip $zip_name $release_files`;
5 changes: 5 additions & 0 deletions lib/utfcpp/v2_0/samples/Makefile
@@ -0,0 +1,5 @@
CC = g++
CFLAGS = -g -Wall -pedantic

docsample: docsample.cpp ../source/utf8.h
$(CC) $(CFLAGS) docsample.cpp -odocsample
52 changes: 52 additions & 0 deletions lib/utfcpp/v2_0/samples/docsample.cpp
@@ -0,0 +1,52 @@
#include "../source/utf8.h"
#include <iostream>
#include <fstream>
#include <string>
#include <vector>


using namespace std;

int main(int argc, char** argv)
{
if (argc != 2) {
cout << "\nUsage: docsample filename\n";
return 0;
}
const char* test_file_path = argv[1];
// Open the test file (must be UTF-8 encoded)
ifstream fs8(test_file_path);
if (!fs8.is_open()) {
cout << "Could not open " << test_file_path << endl;
return 0;
}

unsigned line_count = 1;
string line;
// Play with all the lines in the file
while (getline(fs8, line)) {
// check for invalid utf-8 (for a simple yes/no check, there is also utf8::is_valid function)
string::iterator end_it = utf8::find_invalid(line.begin(), line.end());
if (end_it != line.end()) {
cout << "Invalid UTF-8 encoding detected at line " << line_count << "\n";
cout << "This part is fine: " << string(line.begin(), end_it) << "\n";
}
// Get the line length (at least for the valid part)
int length = utf8::distance(line.begin(), end_it);
cout << "Length of line " << line_count << " is " << length << "\n";

// Convert it to utf-16
vector<unsigned short> utf16line;
utf8::utf8to16(line.begin(), end_it, back_inserter(utf16line));
// And back to utf-8;
string utf8line;
utf8::utf16to8(utf16line.begin(), utf16line.end(), back_inserter(utf8line));
// Confirm that the conversion went OK:
if (utf8line != string(line.begin(), end_it))
cout << "Error in UTF-16 conversion at line: " << line_count << "\n";

line_count++;
}

return 0;
}
34 changes: 34 additions & 0 deletions lib/utfcpp/v2_0/source/utf8.h
@@ -0,0 +1,34 @@
// Copyright 2006 Nemanja Trifunovic

/*
Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:
The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/


#ifndef UTF8_FOR_CPP_2675DCD0_9480_4c0c_B92A_CC14C027B731
#define UTF8_FOR_CPP_2675DCD0_9480_4c0c_B92A_CC14C027B731

#include "utf8/checked.h"
#include "utf8/unchecked.h"

#endif // header guard

0 comments on commit 947a46e

Please sign in to comment.