From 7b11075264442aeb6037ad90ce3950ddc64e3ef3 Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Fri, 4 Jan 2013 22:01:11 +0100 Subject: [PATCH] Nitpicker: move 'asci_to' to public header This function is worth reusing outside of nitpicker. --- os/include/nitpicker_gfx/string.h | 52 ++++++++++++++++++++++++++ os/src/server/nitpicker/genode/main.cc | 32 +--------------- 2 files changed, 53 insertions(+), 31 deletions(-) create mode 100644 os/include/nitpicker_gfx/string.h diff --git a/os/include/nitpicker_gfx/string.h b/os/include/nitpicker_gfx/string.h new file mode 100644 index 0000000000..4b3ed8b84f --- /dev/null +++ b/os/include/nitpicker_gfx/string.h @@ -0,0 +1,52 @@ +/* + * \brief Convert string to color + * \author Norman Feske + * \date 2013-01-04 + */ + +/* + * Copyright (C) 2012 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU General Public License version 2. + */ + +#ifndef _INCLUDE__NITPICKER_GFX__STRING_H_ +#define _INCLUDE__NITPICKER_GFX__STRING_H_ + +/* Genode includes */ +#include + +#include "nitpicker_gfx/color.h" + +namespace Genode { + + /** + * Convert ASCII string to Color + * + * The ASCII string must have the format '#rrggbb' + * + * \return number of consumed characters, or 0 if the string contains + * no valid color + */ + template <> + inline size_t ascii_to(const char *s, Color *result, unsigned) + { + /* validate string */ + if (strlen(s) < 7 || *s != '#') return 0; + + enum { HEX = true }; + + for (unsigned i = 0; i < 6; i++) + if (!is_digit(s[i + 1], HEX)) return 0; + + int red = 16*digit(s[1], HEX) + digit(s[2], HEX), + green = 16*digit(s[3], HEX) + digit(s[4], HEX), + blue = 16*digit(s[5], HEX) + digit(s[6], HEX); + + *result = Color(red, green, blue); + return 7; + } +} + +#endif /* _INCLUDE__NITPICKER_GFX__STRING_H_ */ diff --git a/os/src/server/nitpicker/genode/main.cc b/os/src/server/nitpicker/genode/main.cc index e0a16fb726..e566b514ff 100644 --- a/os/src/server/nitpicker/genode/main.cc +++ b/os/src/server/nitpicker/genode/main.cc @@ -29,6 +29,7 @@ #include #include #include +#include #include /* local includes */ @@ -44,37 +45,6 @@ ** Utilities ** ***************/ -namespace Genode { - - /** - * Convert ASCII string to Color - * - * The ASCII string must have the format '#rrggbb' - * - * \return number of consumed characters, or 0 if the string contains - * no valid color - */ - template <> - inline size_t ascii_to(const char *s, Color *result, unsigned) - { - /* validate string */ - if (strlen(s) != 7 || *s != '#') return 0; - - enum { HEX = true }; - - for (unsigned i = 0; i < 6; i++) - if (!is_digit(s[i + 1], HEX)) return 0; - - int red = 16*digit(s[1], HEX) + digit(s[2], HEX), - green = 16*digit(s[3], HEX) + digit(s[4], HEX), - blue = 16*digit(s[5], HEX) + digit(s[6], HEX); - - *result = Color(red, green, blue); - return 7; - } -} - - /** * Determine session color according to the list of configured policies *