1// LAF Base Library
2// Copyright (c) 2022 Igara Studio S.A.
3// Copyright (c) 2016 David Capello
4//
5// This file is released under the terms of the MIT license.
6// Read LICENSE.txt for more information.
7
8#ifndef BASE_HEX_H_INCLUDED
9#define BASE_HEX_H_INCLUDED
10#pragma once
11
12namespace base {
13
14 inline bool is_hex_digit(const char c) {
15 return ((c >= '0' && c <= '9') ||
16 (c >= 'A' && c <= 'F') ||
17 (c >= 'a' && c <= 'f'));
18 }
19
20 inline int hex_to_int(const char c) {
21 if (c >= '0' && c <= '9') return c - '0';
22 if (c >= 'A' && c <= 'F') return c - 'A' + 10;
23 if (c >= 'a' && c <= 'f') return c - 'a' + 10;
24 return 0;
25 }
26
27} // namespace base
28
29#endif
30