/src/im/default/ftk_input_method_util.c

http://ftk.googlecode.com/ · C · 79 lines · 38 code · 12 blank · 29 comment · 16 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. * History:
  26. * ================================================================
  27. * 2010-02-15 Li XianJing <xianjimli@hotmail.com> created
  28. *
  29. */
  30. #include "ftk_input_method_util.h"
  31. Ret ftk_im_candidate_info_parse(FtkCommitInfo* info, const char* matched, FtkCompare compare)
  32. {
  33. int len = 0;
  34. int candidate_size = 0;
  35. const char* end = matched;
  36. const char* start = matched;
  37. const char* line = matched;
  38. info->candidate_nr = 0;
  39. info->candidates[0] = '\0';
  40. for(;line != NULL;)
  41. {
  42. if(compare(line, info->raw_text) != 0)
  43. {
  44. break;
  45. }
  46. start = strchr(line, ' ');
  47. if(start == NULL) break; else start++;
  48. end = start;
  49. while(*end && *end != ' ' && *end != '\n') end++;
  50. len = end - start;
  51. if((candidate_size + len + 1) < FTK_IM_CANDIDATE_BUFF_LENGTH)
  52. {
  53. memcpy(info->candidates + candidate_size, start, len);
  54. info->candidates[candidate_size + len] ='\0';
  55. candidate_size += len + 1;
  56. info->candidate_nr++;
  57. }
  58. else
  59. {
  60. break;
  61. }
  62. line = strchr(end, '\n');
  63. if(line != NULL) line++;
  64. if(info->candidate_nr > FTK_IM_MAX_CANDIDATES) break;
  65. }
  66. return RET_OK;
  67. }