File: utils.cpp

package info (click to toggle)
scim-unikey 0.3.1+debian-3.1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 2,396 kB
  • ctags: 1,262
  • sloc: sh: 10,650; cpp: 7,490; makefile: 169; sed: 16
file content (62 lines) | stat: -rw-r--r-- 1,056 bytes parent folder | download | duplicates (3)
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
/**
   Scim-Unikey Input Method

   Copyright (C) 2008-2009 Ubuntu-VN <http://www.ubuntu-vn.org>
   Author: Le Quoc Tuan <mr.lequoctuan@gmail.com>
   Home: http://scim-unikey.googlecode.com
   License: GNU LESSER GENERAL PUBLIC LICENSE v2.1
*/

#include <scim.h>
#include "scim_unikey_const.h"

const char *getMacroFile()
{
	scim::String s;
	bool t;

	s = getenv("HOME");
	s.append(SCIM_IMENGINE_UNIKEY_MACROPATH);

	int k=s.length()-1;
	if ((s.at(0)=='\"' && s.at(k)=='\"'))
	{
		s.erase(k, 1);
		s.erase(0, 1);
	}

	return s.c_str();
}

// code from x-unikey, for convert charset that not is XUtf-8
int latinToUtf(unsigned char *dst, unsigned char *src, int inSize, int * pOutSize)
{
	int i;
	int outLeft;
	unsigned char ch;

	outLeft = *pOutSize;

	for (i=0; i<inSize; i++)
	{
		ch = *src++;
		if (ch < 0x80)
		{
			outLeft -= 1;
			if (outLeft >= 0)
				*dst++ = ch;
		}
		else
		{
			outLeft -= 2;
			if (outLeft >= 0)
			{
				*dst++ = (0xC0 | ch >> 6);
				*dst++ = (0x80 | (ch & 0x3F));
			}
		}
	}

	*pOutSize = outLeft;
	return (outLeft >= 0);
}