The SWORD Project  1.9.0.svnversion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
utf8cantillation.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * utf8cantillation.cpp - SWFilter descendant to remove UTF-8 Hebrew
4  * cantillation
5  *
6  * $Id: utf8cantillation.cpp 2980 2013-09-14 21:51:47Z scribe $
7  *
8  * Copyright 2001-2013 CrossWire Bible Society (http://www.crosswire.org)
9  * CrossWire Bible Society
10  * P. O. Box 2528
11  * Tempe, AZ 85280-2528
12  *
13  * This program is free software; you can redistribute it and/or modify it
14  * under the terms of the GNU General Public License as published by the
15  * Free Software Foundation version 2.
16  *
17  * This program is distributed in the hope that it will be useful, but
18  * WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20  * General Public License for more details.
21  *
22  */
23 
24 #include <stdlib.h>
25 #include <stdio.h>
26 #include <utf8cantillation.h>
27 
28 
30 
31 namespace {
32 
33  static const char oName[] = "Hebrew Cantillation";
34  static const char oTip[] = "Toggles Hebrew Cantillation Marks";
35 
36  static const StringList *oValues() {
37  static const SWBuf choices[3] = {"Off", "On", ""};
38  static const StringList oVals(&choices[0], &choices[2]);
39  return &oVals;
40  }
41 }
42 
43 
45 }
46 
47 
49 
50 
51 char UTF8Cantillation::processText(SWBuf &text, const SWKey *key, const SWModule *module) {
52  if (!option) {
53  //The UTF-8 range 0xD6 0x90 to 0xD6 0xAF and 0xD7 0x84 consist of Hebrew cantillation marks so block those out.
54  SWBuf orig = text;
55  const unsigned char* from = (unsigned char*)orig.c_str();
56  for (text = ""; *from; from++) {
57  if (*from != 0xD6) {
58  if (*from == 0xD7 && *(from + 1) == 0x84) {
59  from++;
60  }
61  else {
62  text += *from;
63  }
64  }
65  else if (*(from + 1) < 0x90 || *(from + 1) > 0xAF) {
66  text += *from;
67  from++;
68  text += *from;
69  }
70  else {
71  from++;
72  }
73  }
74  }
75  return 0;
76 }
77 
virtual char processText(SWBuf &text, const SWKey *key=0, const SWModule *module=0)
#define SWORD_NAMESPACE_START
Definition: defs.h:39
Definition: swbuf.h:47
SWText * module
Definition: osis2mod.cpp:105
static const StringList * oValues()
virtual ~UTF8Cantillation()
const char * c_str() const
Definition: swbuf.h:158
std::list< SWBuf > StringList
Definition: swmodule.cpp:91
static const char oName[]
static const char * choices[4]
static const char oTip[]
#define SWORD_NAMESPACE_END
Definition: defs.h:40
Definition: swkey.h:77