PageRenderTime 22ms CodeModel.GetById 14ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/src/im/default/ftk_input_method_util.c

http://ftk.googlecode.com/
C | 79 lines | 38 code | 12 blank | 29 comment | 15 complexity | 79e6cf924a636d040c44201c6ef2f034 MD5 | raw file
 1/*
 2 * File: ftk_input_method_util.c
 3 * Author:  Li XianJing <xianjimli@hotmail.com>
 4 * Brief:   some util functions used by input method.
 5 *
 6 * Copyright (c) 2009 - 2010  Li XianJing <xianjimli@hotmail.com>
 7 *
 8 * Licensed under the Academic Free License version 2.1
 9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23 */
24
25/*
26 * History:
27 * ================================================================
28 * 2010-02-15 Li XianJing <xianjimli@hotmail.com> created
29 *
30 */
31
32#include "ftk_input_method_util.h"
33
34Ret  ftk_im_candidate_info_parse(FtkCommitInfo* info, const char* matched, FtkCompare compare)
35{
36	int len = 0;
37	int candidate_size = 0;
38	const char* end   = matched;
39	const char* start = matched;
40	const char* line  = matched;
41	
42	info->candidate_nr = 0;
43	info->candidates[0] = '\0';
44
45	for(;line != NULL;)
46	{
47		if(compare(line, info->raw_text) != 0)
48		{
49			break;
50		}
51
52		start = strchr(line, ' ');
53		if(start == NULL) break; else start++;
54
55		end   = start;
56		while(*end && *end != ' ' && *end != '\n') end++;
57		
58		len = end - start;
59		if((candidate_size + len + 1) < FTK_IM_CANDIDATE_BUFF_LENGTH)
60		{
61			memcpy(info->candidates + candidate_size, start, len);
62			info->candidates[candidate_size + len] ='\0';
63			candidate_size += len + 1;
64			info->candidate_nr++;	
65		}
66		else
67		{
68			break;
69		}
70
71		line = strchr(end, '\n');
72		if(line != NULL) line++;
73
74		if(info->candidate_nr > FTK_IM_MAX_CANDIDATES) break;
75	}
76
77	return RET_OK;
78}
79