cf2342362a69f5995421c1abf81d814d4261ae1b
[ossec-hids.git] / src / os_regex / os_regex_str.c
1 /*   $OSSEC, os_regex_str.c, v0.1, 2005/12/29, Daniel B. Cid$   */
2
3 /* Copyright (C) 2009 Trend Micro Inc.
4  * All right reserved.
5  *
6  * This program is a free software; you can redistribute it
7  * and/or modify it under the terms of the GNU General Public
8  * License (version 2) as published by the FSF - Free Software
9  * Foundation
10  */
11
12
13 #include <stdio.h>
14 #include <string.h>
15 #include <stdlib.h>
16
17 #include "os_regex.h"
18 #include "os_regex_internal.h"
19
20
21 /** int OS_StrIsNum(char *str) v0.1
22  * Checks if a specific string is numeric (like "129544")
23  */
24 int OS_StrIsNum(const char *str)
25 {
26     if(str == NULL)
27         return(FALSE);
28
29     while(*str != '\0')
30     {
31         if(!_IsD(*str))
32             return(FALSE); /* 0 */
33         str++;
34     }
35
36     return(TRUE);
37 }
38
39
40 /** int OS_StrHowClosedMatch(char *str1, char *str2) v0.1
41  * Returns the number of characters that both strings
42  * have in similar.
43  */
44 size_t OS_StrHowClosedMatch(const char *str1, const char *str2)
45 {
46     size_t count = 0;
47
48     /* They don't match if any of them is null */
49     if(!str1 || !str2)
50     {
51         return(0);
52     }
53
54     do
55     {
56         if(str1[count] != str2[count])
57         {
58             break;
59         }
60
61         count++;
62     }while((str1[count] != '\0') && (str2[count] != '\0'));
63
64     return(count);
65 }
66
67
68 /* EOF */