use icu:: namespace and start isolating icu impl by consistenly using mapnik::value_unicode_string

This commit is contained in:
Dane Springmeyer 2013-08-13 18:52:04 -04:00
parent 80cc235ff9
commit e0026f3df2
26 changed files with 76 additions and 68 deletions

View file

@ -919,7 +919,7 @@ def boost_regex_has_icu(context):
int main()
{
UnicodeString ustr;
icu::UnicodeString ustr;
try {
boost::u32regex pattern = boost::make_u32regex(ustr);
}

View file

@ -32,6 +32,7 @@
// mapnik
#include <mapnik/value_types.hpp>
#include <mapnik/feature.hpp>
#include <mapnik/feature_factory.hpp>
#include <mapnik/feature_kv_iterator.hpp>
@ -121,14 +122,14 @@ boost::python::dict attributes(mapnik::feature_impl const& f)
} // end anonymous namespace
struct UnicodeString_from_python_str
struct unicode_string_from_python_str
{
UnicodeString_from_python_str()
unicode_string_from_python_str()
{
boost::python::converter::registry::push_back(
&convertible,
&construct,
boost::python::type_id<UnicodeString>());
boost::python::type_id<mapnik::value_unicode_string>());
}
static void* convertible(PyObject* obj_ptr)
@ -168,9 +169,9 @@ struct UnicodeString_from_python_str
}
if (value == 0) boost::python::throw_error_already_set();
void* storage = (
(boost::python::converter::rvalue_from_python_storage<UnicodeString>*)
(boost::python::converter::rvalue_from_python_storage<mapnik::value_unicode_string>*)
data)->storage.bytes;
new (storage) UnicodeString(value);
new (storage) mapnik::value_unicode_string(value);
data->convertible = storage;
}
};
@ -219,7 +220,7 @@ void export_feature()
implicitly_convertible<mapnik::value_bool,mapnik::value>();
// http://misspent.wordpress.com/2009/09/27/how-to-write-boost-python-converters/
UnicodeString_from_python_str();
unicode_string_from_python_str();
value_null_from_python();
class_<context_type,context_ptr,boost::noncopyable>

View file

@ -28,6 +28,7 @@
#include <mapnik/debug.hpp>
#include <mapnik/params.hpp>
#include <mapnik/unicode.hpp>
#include <mapnik/value_types.hpp>
#include <mapnik/value.hpp>
// stl
#include <iterator>
@ -82,7 +83,7 @@ struct parameters_pickle_suite : boost::python::pickle_suite
extract<std::string> ex0(obj);
extract<mapnik::value_integer> ex1(obj);
extract<double> ex2(obj);
extract<UnicodeString> ex3(obj);
extract<mapnik::value_unicode_string> ex3(obj);
// TODO - this is never hit - we need proper python string -> std::string to get invoked here
if (ex0.check())
@ -175,7 +176,7 @@ mapnik::value_holder get_param(mapnik::parameter const& p, int index)
}
}
boost::shared_ptr<mapnik::parameter> create_parameter(UnicodeString const& key, mapnik::value_holder const& value)
boost::shared_ptr<mapnik::parameter> create_parameter(mapnik::value_unicode_string const& key, mapnik::value_holder const& value)
{
std::string key_utf8;
mapnik::to_utf8(key, key_utf8);
@ -184,7 +185,7 @@ boost::shared_ptr<mapnik::parameter> create_parameter(UnicodeString const& key,
// needed for Python_Unicode to std::string (utf8) conversion
boost::shared_ptr<mapnik::parameter> create_parameter_from_string(UnicodeString const& key, UnicodeString const& ustr)
boost::shared_ptr<mapnik::parameter> create_parameter_from_string(mapnik::value_unicode_string const& key, mapnik::value_unicode_string const& ustr)
{
std::string key_utf8;
std::string ustr_utf8;

View file

@ -49,13 +49,13 @@ struct unicode_impl
template <typename T>
struct result
{
typedef UnicodeString type;
typedef mapnik::value_unicode_string type;
};
explicit unicode_impl(mapnik::transcoder const& tr)
: tr_(tr) {}
UnicodeString operator()(std::string const& str) const
mapnik::value_unicode_string operator()(std::string const& str) const
{
return tr_.transcode(str.c_str());
}

View file

@ -24,6 +24,7 @@
#define MAPNIK_EXPRESSION_NODE_HPP
// mapnik
#include <mapnik/value_types.hpp>
#include <mapnik/value.hpp>
#include <mapnik/attribute.hpp>
#include <mapnik/expression_node_types.hpp>
@ -87,7 +88,7 @@ struct binary_node
struct regex_match_node
{
regex_match_node (expr_node const& a, UnicodeString const& ustr);
regex_match_node (expr_node const& a, mapnik::value_unicode_string const& ustr);
expr_node expr;
boost::u32regex pattern;
};
@ -95,10 +96,10 @@ struct regex_match_node
struct regex_replace_node
{
regex_replace_node (expr_node const& a, UnicodeString const& ustr, UnicodeString const& f);
regex_replace_node (expr_node const& a, mapnik::value_unicode_string const& ustr, mapnik::value_unicode_string const& f);
expr_node expr;
boost::u32regex pattern;
UnicodeString format;
mapnik::value_unicode_string format;
};
#else

View file

@ -52,9 +52,6 @@
#include <vector>
#include <map>
// uci
#include <unicode/unistr.h>
struct FT_LibraryRec_;
namespace mapnik
@ -106,7 +103,7 @@ public:
size_type size() const;
glyph_ptr get_glyph(unsigned c) const;
char_info character_dimensions(unsigned c);
void get_string_info(string_info & info, UnicodeString const& ustr, char_properties *format);
void get_string_info(string_info & info, mapnik::value_unicode_string const& ustr, char_properties *format);
void set_pixel_sizes(unsigned size);
void set_character_sizes(double size);
private:

View file

@ -25,6 +25,7 @@
// mapnik
#include <mapnik/global.hpp>
#include <mapnik/value_types.hpp>
#include <mapnik/value.hpp>
#include <mapnik/feature.hpp>
#include <mapnik/json/geometry_generator_grammar.hpp>
@ -120,7 +121,7 @@ struct utf8
template <typename T>
struct result { typedef std::string type; };
std::string operator() (UnicodeString const& ustr) const
std::string operator() (mapnik::value_unicode_string const& ustr) const
{
std::string result;
to_utf8(ustr,result);
@ -232,7 +233,7 @@ struct feature_generator_grammar:
karma::rule<OutputIterator, pair_type()> pair;
karma::rule<OutputIterator, void(mapnik::value const&)> value;
karma::rule<OutputIterator, mapnik::value_null()> value_null_;
karma::rule<OutputIterator, UnicodeString()> ustring;
karma::rule<OutputIterator, mapnik::value_unicode_string()> ustring;
typename karma::int_generator<mapnik::value_integer,10, false> int__;
// phoenix functions
phoenix::function<get_id> id_;

View file

@ -26,10 +26,10 @@
// mapnik
#include <mapnik/quad_tree.hpp>
#include <mapnik/noncopyable.hpp>
#include <mapnik/value_types.hpp>
// stl
#include <vector>
#include <unicode/unistr.h>
namespace mapnik
{
@ -142,10 +142,10 @@ public:
struct label
{
label(box2d<double> const& b) : box(b), text() {}
label(box2d<double> const& b, UnicodeString const& t) : box(b), text(t) {}
label(box2d<double> const& b, mapnik::value_unicode_string const& t) : box(b), text(t) {}
box2d<double> box;
UnicodeString text;
mapnik::value_unicode_string text;
};
private:
@ -174,7 +174,7 @@ public:
return true;
}
bool has_placement(box2d<double> const& box, UnicodeString const& text, double distance)
bool has_placement(box2d<double> const& box, mapnik::value_unicode_string const& text, double distance)
{
box2d<double> bigger_box(box.minx() - distance, box.miny() - distance, box.maxx() + distance, box.maxy() + distance);
tree_t::query_iterator itr = tree_.query_in_box(bigger_box);
@ -213,7 +213,7 @@ public:
tree_.insert(label(box), box);
}
void insert(box2d<double> const& box, UnicodeString const& text)
void insert(box2d<double> const& box, mapnik::value_unicode_string const& text)
{
tree_.insert(label(box, text), box);
}

View file

@ -26,6 +26,7 @@
#include <mapnik/text_properties.hpp>
#include <mapnik/text_path.hpp>
#include <mapnik/noncopyable.hpp>
#include <mapnik/value_types.hpp>
// stl
#include <list>
@ -42,14 +43,15 @@ class MAPNIK_DECL processed_text : mapnik::noncopyable
public:
struct processed_expression
{
processed_expression(char_properties const& properties, UnicodeString const& text)
: p(properties), str(text) {}
processed_expression(char_properties const& properties, mapnik::value_unicode_string const& text)
: p(properties),
str(text) {}
char_properties p;
UnicodeString str;
mapnik::value_unicode_string str;
};
public:
processed_text(face_manager<freetype_engine> & font_manager, double scale_factor);
void push_back(char_properties const& properties, UnicodeString const& text);
void push_back(char_properties const& properties, mapnik::value_unicode_string const& text);
unsigned size() const { return expr_list_.size(); }
unsigned empty() const { return expr_list_.empty(); }
void clear();

View file

@ -27,6 +27,7 @@
#include <mapnik/char_info.hpp>
#include <mapnik/pixel_position.hpp>
#include <mapnik/noncopyable.hpp>
#include <mapnik/value_types.hpp>
//stl
#include <vector>
@ -34,9 +35,6 @@
// boost
#include <boost/shared_ptr.hpp>
// uci
#include <unicode/unistr.h>
namespace mapnik
{
@ -45,10 +43,10 @@ class string_info : private mapnik::noncopyable
protected:
typedef std::vector<char_info> characters_t;
characters_t characters_;
UnicodeString text_;
mapnik::value_unicode_string text_;
bool is_rtl;
public:
string_info(UnicodeString const& text)
string_info(mapnik::value_unicode_string const& text)
: characters_(),
text_(text),
is_rtl(false)
@ -69,7 +67,7 @@ public:
characters_.push_back(info);
}
void add_text(UnicodeString const& text)
void add_text(mapnik::value_unicode_string const& text)
{
text_ += text;
}
@ -99,13 +97,14 @@ public:
return at(i);
}
UnicodeString const& get_string() const
mapnik::value_unicode_string const& get_string() const
{
return text_;
}
bool has_line_breaks() const
{
// uint16_t
UChar break_char = '\n';
return (text_.indexOf(break_char) >= 0);
}

View file

@ -28,7 +28,7 @@
#include <mapnik/noncopyable.hpp>
// icu
#include <unicode/unistr.h>
#include <mapnik/value_types.hpp>
#include <unicode/ucnv.h>
// boost
@ -43,7 +43,7 @@ class MAPNIK_DECL transcoder : private mapnik::noncopyable
{
public:
explicit transcoder (std::string const& encoding);
UnicodeString transcode(const char* data, boost::int32_t length = -1) const;
mapnik::value_unicode_string transcode(const char* data, boost::int32_t length = -1) const;
~transcoder();
private:
bool ok_;
@ -52,7 +52,7 @@ private:
}
namespace U_ICU_NAMESPACE {
inline std::size_t hash_value(const UnicodeString& val) {
inline std::size_t hash_value(mapnik::value_unicode_string const& val) {
return val.hashCode();
}
}

View file

@ -42,14 +42,15 @@
// stl
#include <string>
#include <cmath>
// uci
// icu
#include <unicode/unistr.h>
#include <unicode/ustring.h>
namespace mapnik {
inline void to_utf8(UnicodeString const& input, std::string & target)
inline void to_utf8(mapnik::value_unicode_string const& input, std::string & target)
{
if (input.isEmpty()) return;

View file

@ -42,7 +42,7 @@ typedef int value_integer;
#endif
typedef double value_double;
typedef UnicodeString value_unicode_string;
typedef icu::UnicodeString value_unicode_string;
typedef bool value_bool;
struct value_null

View file

@ -42,6 +42,7 @@
#include <mapnik/utils.hpp>
#include <mapnik/feature.hpp>
#include <mapnik/feature_kv_iterator.hpp>
#include <mapnik/value_types.hpp>
#include <mapnik/box2d.hpp>
#include <mapnik/debug.hpp>
#include <mapnik/proj_transform.hpp>
@ -81,7 +82,7 @@ struct attr_value_converter : public boost::static_visitor<mapnik::eAttributeTyp
return mapnik::String;
}
mapnik::eAttributeType operator() (UnicodeString const& /*val*/) const
mapnik::eAttributeType operator() (mapnik::value_unicode_string const& /*val*/) const
{
return mapnik::String;
}

View file

@ -29,6 +29,7 @@
#include <mapnik/feature_layer_desc.hpp>
#include <mapnik/wkb.hpp>
#include <mapnik/unicode.hpp>
#include <mapnik/value_types.hpp>
#include <mapnik/feature_factory.hpp>
// ogr
@ -192,7 +193,7 @@ feature_ptr occi_featureset::next()
case oracle::occi::OCCI_SQLT_TIMESTAMP:
case oracle::occi::OCCI_SQLT_TIMESTAMP_LTZ:
case oracle::occi::OCCI_SQLT_TIMESTAMP_TZ:
feature->put(fld_name, (UnicodeString)tr_->transcode(rs_->getString(i + 1).c_str()));
feature->put(fld_name, static_cast<mapnik::value_unicode_string>(tr_->transcode(rs_->getString(i + 1).c_str())));
break;
case oracle::occi::OCCIINTERVALDS:
case oracle::occi::OCCIINTERVALYM:

View file

@ -30,6 +30,7 @@
#include <mapnik/feature_layer_desc.hpp>
#include <mapnik/wkb.hpp>
#include <mapnik/unicode.hpp>
#include <mapnik/value_types.hpp>
#include <mapnik/feature_factory.hpp>
// ogr
@ -129,8 +130,7 @@ feature_ptr ogr_featureset::next()
case OFTString:
case OFTWideString: // deprecated !
{
UnicodeString ustr = tr_->transcode(poFeature->GetFieldAsString(i));
feature->put( fld_name, ustr);
feature->put( fld_name, tr_->transcode(poFeature->GetFieldAsString(i)));
break;
}

View file

@ -154,8 +154,7 @@ feature_ptr ogr_index_featureset<filterT>::next()
case OFTString:
case OFTWideString: // deprecated !
{
UnicodeString ustr = tr_->transcode(poFeature->GetFieldAsString (i));
feature->put(fld_name,ustr);
feature->put(fld_name,tr_->transcode(poFeature->GetFieldAsString (i)));
break;
}

View file

@ -29,6 +29,7 @@
#include <mapnik/feature_layer_desc.hpp>
#include <mapnik/wkb.hpp>
#include <mapnik/unicode.hpp>
#include <mapnik/value_types.hpp>
#include <mapnik/feature_factory.hpp>
// ogr
@ -123,8 +124,7 @@ feature_ptr sqlite_featureset::next()
{
int text_col_size;
const char * text_data = rs_->column_text(i, text_col_size);
UnicodeString ustr = tr_->transcode(text_data, text_col_size);
feature->put(fld_name_str, ustr);
feature->put(fld_name_str, tr_->transcode(text_data, text_col_size));
break;
}

View file

@ -1,6 +1,7 @@
// mapnik
#include <mapnik/feature_factory.hpp>
#include <mapnik/geometry.hpp>
#include <mapnik/value_types.hpp>
// boost
#include <boost/make_shared.hpp>
@ -32,7 +33,7 @@ mapnik::feature_ptr hello_featureset::next()
++feature_id_;
// create an attribute pair of key:value
UnicodeString ustr = tr_->transcode("hello world!");
mapnik::value_unicode_string ustr = tr_->transcode("hello world!");
feature->put(attribute,ustr);
// we need a geometry to display so just for fun here

View file

@ -21,17 +21,18 @@
*****************************************************************************/
#include <mapnik/expression_node.hpp>
#include <mapnik/value_types.hpp>
namespace mapnik
{
#if defined(BOOST_REGEX_HAS_ICU)
regex_match_node::regex_match_node (expr_node const& a, UnicodeString const& ustr)
regex_match_node::regex_match_node (expr_node const& a, mapnik::value_unicode_string const& ustr)
: expr(a),
pattern(boost::make_u32regex(ustr)) {}
regex_replace_node::regex_replace_node (expr_node const& a, UnicodeString const& ustr, UnicodeString const& f)
regex_replace_node::regex_replace_node (expr_node const& a, mapnik::value_unicode_string const& ustr, mapnik::value_unicode_string const& f)
: expr(a),
pattern(boost::make_u32regex(ustr)),
format(f) {}

View file

@ -27,6 +27,7 @@
#include <mapnik/expression_node_types.hpp>
#include <mapnik/expression_node.hpp>
#include <mapnik/attribute.hpp>
#include <mapnik/value_types.hpp>
#include <mapnik/value.hpp>
// boost
@ -35,10 +36,6 @@
#include <boost/regex/icu.hpp> // for u32regex
#endif
// icu
#include <unicode/unistr.h> // for UnicodeString
namespace mapnik
{
@ -96,7 +93,7 @@ struct expression_string : boost::static_visitor<void>
str_ +=".match('";
#if defined(BOOST_REGEX_HAS_ICU)
std::string utf8;
UnicodeString ustr = UnicodeString::fromUTF32( &x.pattern.str()[0] ,x.pattern.str().length());
mapnik::value_unicode_string ustr = mapnik::value_unicode_string::fromUTF32( &x.pattern.str()[0] ,x.pattern.str().length());
to_utf8(ustr,utf8);
str_ += utf8;
#else
@ -112,7 +109,7 @@ struct expression_string : boost::static_visitor<void>
str_ += "'";
#if defined(BOOST_REGEX_HAS_ICU)
std::string utf8;
UnicodeString ustr = UnicodeString::fromUTF32( &x.pattern.str()[0] ,x.pattern.str().length());
mapnik::value_unicode_string ustr = mapnik::value_unicode_string::fromUTF32( &x.pattern.str()[0] ,x.pattern.str().length());
to_utf8(ustr,utf8);
str_ += utf8;
str_ +="','";

View file

@ -25,6 +25,7 @@
#include <mapnik/font_engine_freetype.hpp>
#include <mapnik/text_properties.hpp>
#include <mapnik/graphics.hpp>
#include <mapnik/value_types.hpp>
#if defined(GRID_RENDERER)
#include <mapnik/grid/grid.hpp>
@ -350,12 +351,12 @@ char_info font_face_set::character_dimensions(unsigned int c)
}
void font_face_set::get_string_info(string_info & info, UnicodeString const& ustr, char_properties *format)
void font_face_set::get_string_info(string_info & info, mapnik::value_unicode_string const& ustr, char_properties *format)
{
double avg_height = character_dimensions('X').height();
UErrorCode err = U_ZERO_ERROR;
UnicodeString reordered;
UnicodeString shaped;
mapnik::value_unicode_string reordered;
mapnik::value_unicode_string shaped;
int32_t length = ustr.length();

View file

@ -27,6 +27,7 @@
#include <mapnik/text_properties.hpp>
#include <mapnik/processed_text.hpp>
#include <mapnik/xml_node.hpp>
#include <mapnik/value_types.hpp>
// boost
#include <boost/property_tree/ptree.hpp>
@ -53,7 +54,7 @@ node_ptr text_node::from_xml(xml_node const& xml)
void text_node::apply(char_properties const& p, feature_impl const& feature, processed_text &output) const
{
UnicodeString text_str = boost::apply_visitor(evaluate<feature_impl,value_type>(feature), *text_).to_unicode();
mapnik::value_unicode_string text_str = boost::apply_visitor(evaluate<feature_impl,value_type>(feature), *text_).to_unicode();
if (p.text_transform == UPPERCASE)
{
text_str = text_str.toUpper();

View file

@ -23,11 +23,12 @@
#include <mapnik/processed_text.hpp>
#include <mapnik/config_error.hpp>
#include <mapnik/font_engine_freetype.hpp>
#include <mapnik/value_types.hpp>
namespace mapnik
{
void processed_text::push_back(char_properties const& properties, UnicodeString const& text)
void processed_text::push_back(char_properties const& properties, mapnik::value_unicode_string const& text)
{
expr_list_.push_back(processed_expression(properties, text));
}

View file

@ -22,6 +22,7 @@
// mapnik
#include <mapnik/unicode.hpp>
#include <mapnik/value_types.hpp>
// stl
#include <cstdlib>
@ -39,11 +40,11 @@ transcoder::transcoder (std::string const& encoding)
// TODO ??
}
UnicodeString transcoder::transcode(const char* data, boost::int32_t length) const
mapnik::value_unicode_string transcoder::transcode(const char* data, boost::int32_t length) const
{
UErrorCode err = U_ZERO_ERROR;
UnicodeString ustr(data,length,conv_,err);
mapnik::value_unicode_string ustr(data,length,conv_,err);
if (ustr.isBogus())
{
ustr.remove();

View file

@ -17,6 +17,7 @@
#include <mapnik/image_util.hpp>
#include <mapnik/color_factory.hpp>
#include <mapnik/save_map.hpp>
#include <mapnik/value_types.hpp>
#include <vector>
#include <algorithm>
@ -40,7 +41,7 @@ int main(int argc, char** argv)
ctx->push("name");
mapnik::feature_ptr feature(mapnik::feature_factory::create(ctx,1));
mapnik::transcoder tr("utf-8");
UnicodeString ustr = tr.transcode("hello world!");
mapnik::value_unicode_string ustr = tr.transcode("hello world!");
feature->put("name",ustr);
mapnik::geometry_type * pt = new mapnik::geometry_type(mapnik::Point);
pt->move_to(128,128);