aboutsummaryrefslogtreecommitdiffstats
path: root/src/modules/filters/utf8cantillation.cpp
blob: 8884c6274beb84a8bc8bb91807f0ab950c3b2807 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/******************************************************************************
 *
 * UTF8Cantillation - SWFilter decendant to remove UTF-8 Hebrew cantillation
 *
 */


#include <stdlib.h>
#include <stdio.h>
#include <utf8cantillation.h>

SWORD_NAMESPACE_START

const char UTF8Cantillation::on[] = "On";
const char UTF8Cantillation::off[] = "Off";
const char UTF8Cantillation::optName[] = "Hebrew Cantillation";
const char UTF8Cantillation::optTip[] = "Toggles Hebrew Cantillation Marks";

UTF8Cantillation::UTF8Cantillation() {
	option = false;
	options.push_back(on);
	options.push_back(off);
}

UTF8Cantillation::~UTF8Cantillation(){};

void UTF8Cantillation::setOptionValue(const char *ival)
{
	option = (!stricmp(ival, on));
}

const char *UTF8Cantillation::getOptionValue()
{
	return (option) ? on:off;
}

char UTF8Cantillation::ProcessText(char *text, int maxlen, const SWKey *key, const SWModule *module)
{
	if (!option) {
	unsigned char *to, *from;
	to = (unsigned char*)text;
	//The UTF-8 range 0xD6 0x90 to 0xD6 0xAF and 0xD7 0x84 consist of Hebrew cantillation marks so block those out.
	for (from = (unsigned char*)text; *from; from++) {
	  if (*from != 0xD6) {
	    if (*from == 0xD7 && *(from + 1) == 0x84) {
	      from++;
	    }
	    else {
	      *to++ = *from;
	    }
	  }
	  else if (*(from + 1) < 0x90 || *(from + 1) > 0xAF) {
	    *to++ = *from;
	    from++;
	    *to++ = *from;
	  }
          else {
                from++;
          }
	}
	*to++ = 0;
	*to = 0;
     }
	return 0;
}

SWORD_NAMESPACE_END