Commit feb80eb1 authored by daniel_e's avatar daniel_e
Browse files

(contains_null): Remove.

(color_to_string): Implement.
(shell_pattern_to_regex): Handle alternative syntax '^' for negation
of character classes properly.
parent 7e6680c8
2002-12-25 Daniel Elstner <daniel.elstner@gmx.net>
* src/stringutils.{cc,h} (contains_null): Remove.
(color_to_string): Implement.
(shell_pattern_to_regex): Handle alternative syntax '^' for
negation of character classes properly.
2002-12-25 Daniel Elstner <daniel.elstner@gmx.net>
* src/miscutils.h (ScopedArray<>): New little utility template
......
......@@ -22,8 +22,10 @@
#include <glib.h>
#include <glibmm.h>
#include <gdkmm/color.h>
#include <cstring>
#include <algorithm>
#include <iomanip>
#include <sstream>
#include <utility>
#include <vector>
......@@ -64,6 +66,11 @@ bool IsSignificantEncodingChar::operator()(char c) const
return true;
}
unsigned int scale_to_8bit(unsigned int value)
{
return std::min(255u, (value + 128) / 256);
}
inline
bool ascii_isodigit(char c)
{
......@@ -340,14 +347,12 @@ bool Util::encodings_equal(const std::string& lhs, const std::string& rhs)
return (lhs_pos == lhs_end && rhs_pos == rhs_end);
}
bool Util::contains_null(const char* pbegin, const char* pend)
{
return (std::find(pbegin, pend, '\0') != pend);
}
Glib::ustring Util::shell_pattern_to_regex(const Glib::ustring& pattern)
{
std::string result = "\\A";
std::string result;
result.reserve(std::max<std::string::size_type>(32, 2 * pattern.bytes()));
result += "\\A";
std::string::const_iterator p = pattern.raw().begin();
const std::string::const_iterator pend = pattern.raw().end();
......@@ -404,8 +409,7 @@ Glib::ustring Util::shell_pattern_to_regex(const Glib::ustring& pattern)
{
case ']':
result += ']';
if(!((p[-1] == '[') || (p[-1] == '!' && p[-2] == '[')))
in_cclass = false;
in_cclass = ((p[-1] == '[') || ((p[-1] == '!' || p[-1] == '^') && p[-2] == '['));
break;
case '!':
......@@ -413,8 +417,8 @@ Glib::ustring Util::shell_pattern_to_regex(const Glib::ustring& pattern)
break;
case '\\':
result += "\\\\";
break;
result += '\\';
// fallthrough
default:
result += *p;
......@@ -638,3 +642,22 @@ Glib::ustring Util::transform_pathname(const Glib::ustring& path, bool shorten)
return path;
}
Glib::ustring Util::color_to_string(const Gdk::Color& color)
{
std::ostringstream output;
#if REGEXXER_HAVE_STD_LOCALE
output.imbue(std::locale::classic());
#endif
output.setf(std::ios::hex, std::ios::basefield);
output.setf(std::ios::uppercase);
output.fill('0');
output << '#' << std::setw(2) << scale_to_8bit(color.get_red())
<< std::setw(2) << scale_to_8bit(color.get_green())
<< std::setw(2) << scale_to_8bit(color.get_blue());
return output.str();
}
......@@ -25,6 +25,8 @@
#include <vector>
#include <glibmm/ustring.h>
namespace Gdk { class Color; }
namespace Util
{
......@@ -34,7 +36,6 @@ typedef std::vector< std::pair<int,int> > CaptureVector;
void trim_whitespace(Glib::ustring::const_iterator& pbegin, Glib::ustring::const_iterator& pend);
bool validate_encoding(const std::string& encoding);
bool encodings_equal(const std::string& lhs, const std::string& rhs);
bool contains_null(const char* pbegin, const char* pend);
Glib::ustring shell_pattern_to_regex(const Glib::ustring& pattern);
std::string substitute_references(const std::string& substitution,
......@@ -53,6 +54,8 @@ inline Glib::ustring shorten_pathname(const Glib::ustring& path)
inline Glib::ustring expand_pathname(const Glib::ustring& path)
{ return transform_pathname(path, false); }
Glib::ustring color_to_string(const Gdk::Color& color);
} // namespace Util
#endif /* REGEXXER_STRINGUTILS_H_INCLUDED */
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment