File: lib_utils.cpp

package info (click to toggle)
sdcv 0.3.4-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 2,644 kB
  • ctags: 1,207
  • sloc: sh: 9,235; ansic: 7,803; cpp: 2,613; makefile: 485; yacc: 316; sed: 16
file content (51 lines) | stat: -rw-r--r-- 1,081 bytes parent folder | download
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
#include <cstring>
#include <cctype>

#include "lib_utils.h"

gint stardict_strcmp(const gchar *s1, const gchar *s2)
{
  gint a = g_ascii_strcasecmp(s1, s2);
  if(0==a)
    return strcmp(s1, s2);
  else
    return a;
}

bool bIsPureEnglish(const gchar *str) // i think this should work even when it is UTF8 string :).
{
  for(gint i=0; str[i]!=0; i++)
    if(!isascii(str[i]))
      return false;
        
  return true;
}

gchar* GetHeadWord(gchar *str)
{
  while(g_ascii_isspace(*str))
    str++;
  glong len = g_utf8_strlen(str, -1);
  if(len){
    gchar *last_str = g_utf8_offset_to_pointer(str, len-1);
    gunichar last = g_utf8_get_char(last_str);
    while((g_unichar_isspace(last) || g_unichar_ispunct(last)) ||
	  g_unichar_isdigit(last)){
      *last_str = '\0';
      last_str = g_utf8_find_prev_char(str, last_str);
      if(!last_str)
	break;
      last = g_utf8_get_char(last_str);
    }
  }
  return str;
}

bool bContainRule(const gchar* sWord)
{  
  for(gint i=0; sWord[i]!=0; i++)
    if(sWord[i]=='*' || sWord[i]=='?')
      return true;
    
  return false;
}