Update some code.
This commit is contained in:
@@ -306,47 +306,35 @@ int find_arg_uint ( const char * const key, unsigned int *val )
|
|||||||
|
|
||||||
char helper_parse_char ( const char *arg )
|
char helper_parse_char ( const char *arg )
|
||||||
{
|
{
|
||||||
int len = strlen ( arg );
|
const size_t len = strlen ( arg );
|
||||||
// If the length is 1, it is not escaped.
|
// If the length is 1, it is not escaped.
|
||||||
if ( len == 1 ) {
|
if ( len == 1 ) {
|
||||||
return arg[0];
|
return arg[0];
|
||||||
}
|
}
|
||||||
// If the length is 2 and the first character is '\', we unescape it.
|
// If the length is 2 and the first character is '\', we unescape it.
|
||||||
if ( len == 2 && arg[0] == '\\' ) {
|
if ( len == 2 && arg[0] == '\\' ) {
|
||||||
|
switch ( arg[1] )
|
||||||
|
{
|
||||||
// New line
|
// New line
|
||||||
if ( arg[1] == 'n' ) {
|
case 'n': return '\n';
|
||||||
return '\n';
|
|
||||||
}
|
|
||||||
// Bell
|
// Bell
|
||||||
else if ( arg[1] == 'a' ) {
|
case 'a': return '\a';
|
||||||
return '\a';
|
|
||||||
}
|
|
||||||
// Backspace
|
// Backspace
|
||||||
else if ( arg[1] == 'b' ) {
|
case 'b': return '\b';
|
||||||
return '\b';
|
|
||||||
}
|
|
||||||
// Tab
|
// Tab
|
||||||
else if ( arg[1] == 't' ) {
|
case 't': return '\t';
|
||||||
return '\t';
|
|
||||||
}
|
|
||||||
// Vertical tab
|
// Vertical tab
|
||||||
else if ( arg[1] == 'v' ) {
|
case 'v': return '\v';
|
||||||
return '\v';
|
|
||||||
}
|
|
||||||
// Form feed
|
// Form feed
|
||||||
else if ( arg[1] == 'f' ) {
|
case 'f': return '\f';
|
||||||
return '\f';
|
|
||||||
}
|
|
||||||
// Carriage return
|
// Carriage return
|
||||||
else if ( arg[1] == 'r' ) {
|
case 'r': return '\r';
|
||||||
return '\r';
|
|
||||||
}
|
|
||||||
// Forward slash
|
// Forward slash
|
||||||
else if ( arg[1] == '\\' ) {
|
case '\\': return '\\';
|
||||||
return '\\';
|
// 0 line.
|
||||||
}
|
case '0': return '\0';
|
||||||
else if ( arg[1] == '0' ) {
|
default:
|
||||||
return '\0';
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( len > 2 && arg[0] == '\\' && arg[1] == 'x' ) {
|
if ( len > 2 && arg[0] == '\\' && arg[1] == 'x' ) {
|
||||||
@@ -397,13 +385,11 @@ PangoAttrList *token_match_get_pango_attr ( GRegex **tokens, const char *input,
|
|||||||
|
|
||||||
int token_match ( GRegex * const *tokens, const char *input )
|
int token_match ( GRegex * const *tokens, const char *input )
|
||||||
{
|
{
|
||||||
int match = 1;
|
int match = ( tokens != NULL );
|
||||||
// Do a tokenized match.
|
// Do a tokenized match.
|
||||||
if ( tokens ) {
|
|
||||||
for ( int j = 0; match && tokens[j]; j++ ) {
|
for ( int j = 0; match && tokens[j]; j++ ) {
|
||||||
match = g_regex_match ( (const GRegex *) tokens[j], input, 0, NULL );
|
match = g_regex_match ( (const GRegex *) tokens[j], input, 0, NULL );
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return match;
|
return match;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -614,26 +600,25 @@ char *rofi_expand_path ( const char *input )
|
|||||||
|
|
||||||
unsigned int levenshtein ( const char *needle, const char *haystack )
|
unsigned int levenshtein ( const char *needle, const char *haystack )
|
||||||
{
|
{
|
||||||
unsigned int x, y, lastdiag, olddiag;
|
const size_t needlelen = g_utf8_strlen ( needle, -1 );
|
||||||
size_t needlelen = g_utf8_strlen ( needle, -1 );
|
const size_t haystacklen = g_utf8_strlen ( haystack, -1 );
|
||||||
size_t haystacklen = g_utf8_strlen ( haystack, -1 );
|
|
||||||
unsigned int column[needlelen + 1];
|
unsigned int column[needlelen + 1];
|
||||||
for ( y = 0; y <= needlelen; y++ ) {
|
for ( unsigned int y = 0; y <= needlelen; y++ ) {
|
||||||
column[y] = y;
|
column[y] = y;
|
||||||
}
|
}
|
||||||
for ( x = 1; x <= haystacklen; x++ ) {
|
for ( unsigned int x = 1; x <= haystacklen; x++ ) {
|
||||||
const char *needles = needle;
|
const char *needles = needle;
|
||||||
column[0] = x;
|
column[0] = x;
|
||||||
gunichar haystackc = g_utf8_get_char ( haystack );
|
gunichar haystackc = g_utf8_get_char ( haystack );
|
||||||
if ( !config.case_sensitive ) {
|
if ( !config.case_sensitive ) {
|
||||||
haystackc = g_unichar_tolower ( haystackc );
|
haystackc = g_unichar_tolower ( haystackc );
|
||||||
}
|
}
|
||||||
for ( y = 1, lastdiag = x - 1; y <= needlelen; y++ ) {
|
for ( unsigned int y = 1, lastdiag = x - 1; y <= needlelen; y++ ) {
|
||||||
gunichar needlec = g_utf8_get_char ( needles );
|
gunichar needlec = g_utf8_get_char ( needles );
|
||||||
if ( !config.case_sensitive ) {
|
if ( !config.case_sensitive ) {
|
||||||
needlec = g_unichar_tolower ( needlec );
|
needlec = g_unichar_tolower ( needlec );
|
||||||
}
|
}
|
||||||
olddiag = column[y];
|
unsigned int olddiag = column[y];
|
||||||
column[y] = MIN3 ( column[y] + 1, column[y - 1] + 1, lastdiag + ( needlec == haystackc ? 0 : 1 ) );
|
column[y] = MIN3 ( column[y] + 1, column[y - 1] + 1, lastdiag + ( needlec == haystackc ? 0 : 1 ) );
|
||||||
lastdiag = olddiag;
|
lastdiag = olddiag;
|
||||||
needles = g_utf8_next_char ( needles );
|
needles = g_utf8_next_char ( needles );
|
||||||
|
Reference in New Issue
Block a user