Skip to content

Commit

Permalink
Initial import
Browse files Browse the repository at this point in the history
Importing utf8 cpp 2.3.4 to GitHub.
  • Loading branch information
nemtrif committed Aug 16, 2015
1 parent 6bb44ed commit 46d0d80
Show file tree
Hide file tree
Showing 24 changed files with 3,492 additions and 2 deletions.
1,133 changes: 1,131 additions & 2 deletions README.md

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions buildrelease.pl
Original file line number Diff line number Diff line change
@@ -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 samples/Makefile
Original file line number Diff line number Diff line change
@@ -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 samples/docsample.cpp
Original file line number Diff line number Diff line change
@@ -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 source/utf8.h
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit 46d0d80

Please sign in to comment.