Remove unnecessary setting
[platform/core/system/sensord.git] / src / sensorctl / util.cpp
1 /*
2  * sensorctl
3  *
4  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 #include <stdlib.h>
21 #include "util.h"
22
23 bool util::is_number(const char *value)
24 {
25         if (value == NULL || *value == 0)
26                 return false;
27
28         while (*value) {
29                 if (*value < '0' || *value > '9')
30                         return false;
31                 value++;
32         }
33
34         return true;
35 }
36
37 bool util::is_hex(const char *value)
38 {
39         if (value == NULL || *value == 0)
40                 return false;
41
42         if (value[0] != '0')
43                 return false;
44
45         if (value[1] != 'x' && value[1] != 'X')
46                 return false;
47
48         value += 2;
49
50         while (*value) {
51                 if ((*value < '0' || *value > '9') &&
52                         (*value < 'a' || *value > 'f') &&
53                         (*value < 'A' || *value > 'F'))
54                         return false;
55                 value++;
56         }
57
58         return true;
59 }