The SWORD Project  1.9.0.svnversion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
utf8scsu.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * utf8scsu.cpp - SWFilter descendant to convert UTF-8 to SCSU
4  *
5  * $Id: utf8scsu.cpp 3618 2019-04-14 22:30:32Z scribe $
6  *
7  * Copyright 2001-2014 CrossWire Bible Society (http://www.crosswire.org)
8  * CrossWire Bible Society
9  * P. O. Box 2528
10  * Tempe, AZ 85280-2528
11  *
12  * This program is free software; you can redistribute it and/or modify it
13  * under the terms of the GNU General Public License as published by the
14  * Free Software Foundation version 2.
15  *
16  * This program is distributed in the hope that it will be useful, but
17  * WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * General Public License for more details.
20  *
21  */
22 
23 #ifdef _ICU_
24 
25 #include <utf8scsu.h>
26 #include <swbuf.h>
27 
29 
30 
32  // initialize SCSU converter
33  scsuConv = ucnv_open("SCSU", &err);
34 
35  // initialize UTF-8 converter
36  utf8Conv = ucnv_open("UTF-8", &err);
37 }
38 
40  ucnv_close(scsuConv);
41  ucnv_close(utf8Conv);
42 }
43 
44 char UTF8SCSU::processText(SWBuf &text, const SWKey *key, const SWModule *module) {
45  if ((unsigned long)key < 2) // hack, we're en(1)/de(0)ciphering
46  return -1;
47 
48  err = U_ZERO_ERROR;
49  icu::UnicodeString utf16Text(text.getRawData(), text.length(), utf8Conv, err);
50  err = U_ZERO_ERROR;
51  int32_t len = utf16Text.extract(text.getRawData(), text.size(), scsuConv, err);
52  if (len > (int32_t)text.size()+1) {
53  text.setSize(len+1);
54  utf16Text.extract(text.getRawData(), text.size(), scsuConv, err);
55  }
56 
57  return 0;
58 }
59 
61 #endif
#define SWORD_NAMESPACE_START
Definition: defs.h:39
Definition: swbuf.h:47
unsigned long length() const
Definition: swbuf.h:197
SWText * module
Definition: osis2mod.cpp:105
char * getRawData()
Definition: swbuf.h:379
virtual char processText(SWBuf &text, const SWKey *key=0, const SWModule *module=0)
unsigned long size() const
Definition: swbuf.h:185
UConverter * scsuConv
Definition: utf8scsu.h:41
UErrorCode err
Definition: utf8scsu.h:43
UConverter * utf8Conv
Definition: utf8scsu.h:42
#define SWORD_NAMESPACE_END
Definition: defs.h:40
Definition: swkey.h:77
void setSize(unsigned long len)
Definition: swbuf.h:255