-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Importing utf8 cpp 2.3.4 to GitHub.
- Loading branch information
Showing
24 changed files
with
3,492 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.