diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2010-03-28 16:53:35 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2010-03-28 16:53:35 +0200 |
commit | 4332a60585a14ff51bc54d29a4a81d37b3b1df81 (patch) | |
tree | fd3b807e3f5b3841371d509505a50498d21a2f99 /libxsde/xsde/cxx/serializer/validating/string-common.cxx | |
parent | c2d201480002a24c05f1f4bc934036555b79cad6 (diff) |
Validate enumerations in the xsd:string parser/serializer
Diffstat (limited to 'libxsde/xsde/cxx/serializer/validating/string-common.cxx')
-rw-r--r-- | libxsde/xsde/cxx/serializer/validating/string-common.cxx | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/libxsde/xsde/cxx/serializer/validating/string-common.cxx b/libxsde/xsde/cxx/serializer/validating/string-common.cxx new file mode 100644 index 0000000..20a1b34 --- /dev/null +++ b/libxsde/xsde/cxx/serializer/validating/string-common.cxx @@ -0,0 +1,69 @@ +// file : xsde/cxx/serializer/validating/string-common.cxx +// author : Boris Kolpackov <boris@codesynthesis.com> +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include <string.h> // strlen, strcmp +#include <xsde/cxx/serializer/validating/string-common.hxx> + +namespace xsde +{ + namespace cxx + { + namespace serializer + { + namespace validating + { + void string_common:: + validate_facets (const char* s, +#ifdef XSDE_STL + size_t n, +#endif + const string_facets::facets& f, + context& ctx) + { +#ifndef XSDE_STL + size_t n; + if (f.length_set_ || f.min_length_set_ || f.max_length_set_) + n = strlen (s); +#endif + + if (f.length_set_ && n != f.length_) + { + ctx.schema_error (schema_error::length_not_equal_prescribed); + return; + } + + if (f.min_length_set_ && n < f.min_length_) + { + ctx.schema_error (schema_error::length_less_than_min); + return; + } + + if (f.max_length_set_ && n > f.max_length_) + { + ctx.schema_error (schema_error::length_greater_than_max); + return; + } + + if (f.enum_count_ != 0) + { + size_t i = 0; + + for (; i < f.enum_count_; ++i) + { + if (strcmp (s, f.enum_[i]) == 0) + break; + } + + if (i == f.enum_count_) + { + ctx.schema_error (schema_error::value_not_in_enumeration); + return; + } + } + } + } + } + } +} |