File: nsMigemo.cpp

package info (click to toggle)
cmigemo 1:1.2+gh0.20150404-7
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 1,672 kB
  • sloc: ansic: 2,617; cs: 188; makefile: 174; sh: 107; cpp: 67; perl: 59; csh: 49
file content (43 lines) | stat: -rw-r--r-- 1,133 bytes parent folder | download | duplicates (4)
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
// Copyright 2005 MURAOKA Taro(KoRoN)/KaoriYa

#include "nsMigemo.h"
#include "nsStringAPI.h"

#define MIGEMO_DICTPATH "C:/migemo/utf-8.d/migemo-dict"

NS_IMPL_ISUPPORTS1(nsMigemo, nsIMigemo);

migemo* nsMigemo::migemoObject = NULL;

nsMigemo::nsMigemo()
{
    if (nsMigemo::migemoObject == NULL)
    {
	migemo* obj = migemo_open(MIGEMO_DICTPATH);
	if (obj != NULL && migemo_is_enable(obj) != 0)
	{
	    migemo_set_operator(obj, MIGEMO_OPINDEX_NEST_IN, (const unsigned char*)"(?:");
	    migemo_set_operator(obj, MIGEMO_OPINDEX_NEWLINE, (const unsigned char*)"\\s*");
	    nsMigemo::migemoObject = obj;
	}
    }
}

nsMigemo::~nsMigemo()
{
}

/* AUTF8String query (in AUTF8String key); */
NS_IMETHODIMP
nsMigemo::Query(const nsACString & key, nsACString & _retval)
{
    if (nsMigemo::migemoObject == NULL)
	return NS_ERROR_NOT_INITIALIZED;
    unsigned char* answer = migemo_query(nsMigemo::migemoObject,
	    (const unsigned char*)key.BeginReading());
    if (answer == NULL)
	return NS_ERROR_FAILURE;
    _retval.Assign((const nsACString::char_type*)answer);
    migemo_release(nsMigemo::migemoObject, answer);
    return NS_OK;
}