You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

146 lines
3.6 KiB

9 years ago
About
==========
9 years ago
9 years ago
Cgo binding for icu4c C library detection and conversion functions. Guaranteed compatibility with version 50.1.
Installation
==========
Installation consists of several simple steps. They may be a bit different on your target system (e.g. require more permissions) so adapt them to the parameters of your system.
9 years ago
### Install build-essential
Make sure you have **build-essential** installed. Otherwise icu would fail on the configuration stage.
Installation example using apt-get (Ubuntu):
```
sudo apt-get install build-essential
```
9 years ago
### Install pkg-config
Make sure you have **pkg-config** installed.
Installation example using apt-get (Ubuntu):
```
sudo apt-get install pkg-config
```
9 years ago
### Get icu4c C library code
9 years ago
Download and unarchive original icu4c archive from [icu download section](http://site.icu-project.org/download).
Example (for version 62.1):
9 years ago
```
wget http://download.icu-project.org/files/icu4c/62.1/icu4c-62_1-src.zip
tar -zxvf icu4c-62_1-src.zip
9 years ago
mv -i ./icu ~/where-you-store-libs
```
9 years ago
### Build and install icu4c C library
From the directory, where you unarchived icu4c, run:
```
cd source
./configure
make
sudo make install
9 years ago
sudo ldconfig
9 years ago
```
### Install Go wrapper
```
go get gitlab.com/lupine/icu
go test gitlab.com/lupine/icu (must PASS)
9 years ago
```
Installation notes
==========
* Make sure that you have your local library paths set correctly and that installation was successful. Otherwise, **go build** or **go test** may fail.
* icu4c is installed in your local library directory (e.g. **/usr/local/lib**) and puts its libraries there. This path should be registered in your system (using ldconfig or exporting LD_LIBRARY_PATH, etc.) or the linker would fail.
* icu4c installs its header files to local include folders (e.g. **/usr/local/include/unicode**) so there is no need to have additional .h files with this package, but the system must be properly set up to detect .h files in those directories.
Usage
==========
Note: check icu documentation for returned encoding identifiers.
Detector
----------
```go
// Create detector
detector, err := NewCharsetDetector()
if err != nil {
//... Handle error ...
}
defer detector.Close()
// Guess encoding
encMatches, err := detector.GuessCharset(encodedText)
if err != nil {
//... Handle error ...
}
// Get charset with max confidence (goes first)
maxenc := encMatches[0].Charset
// Use maxenc.
// ...
```
Converter
----------
```go
...
// Create converter
converter := NewCharsetConverter(DefaultMaxTextSize)
// Convert to utf-8
converted, err := converter.ConvertToUtf8(encodedText, maxenc)
if nil != err {
//... Handle error ...
}
```
Usage notes
==========
* Check **NewCharsetConverter** func comments for details on max text size parameter.
* Often you would use detector and converter in pair. So, the 'converter' usage example actually continues the 'detector' example and uses the 'maxenc' result from it.
More info
----------
9 years ago
For more information on icu refer to the original [website](http://site.icu-project.org/), which contains links on theory and other details.
9 years ago
icu4c Licence
==========
ICU is released under a nonrestrictive open source license that is suitable for use with both commercial software and with other open source or free software.
[LICENCE file](https://gitlab.com/lupine/icu/blob/master/LICENCE_icu)
9 years ago
Licence
==========
The `lupine/icu` binding is released under the [BSD Licence](http://opensource.org/licenses/bsd-license.php)
[LICENCE file](https://gitlab.com/lupine/icu/blob/master/LICENCE)
9 years ago
`lupine/icu` is almost entirely based on [`goodsign/icu`](https://github.com/goodsign/icu),
but contains a few changes relative to that fine project.