diff --git a/include/xlnt/cell/cell.hpp b/include/xlnt/cell/cell.hpp index f0f92c5d..ef2e3c2a 100644 --- a/include/xlnt/cell/cell.hpp +++ b/include/xlnt/cell/cell.hpp @@ -24,12 +24,12 @@ #pragma once #include +#include #include #include -#include -#include +#include "xlnt_config.hpp" namespace xlnt { @@ -87,7 +87,7 @@ public: /// /// Return a map of error strings such as \#DIV/0! and their associated indices. /// - static const std::unordered_map &error_codes(); + static const std::unordered_map &error_codes(); // TODO: Should it be possible to construct and use a cell without a parent worksheet? //(cont'd) If so, it would need to be responsible for allocating and deleting its PIMPL. @@ -121,7 +121,7 @@ public: /// /// Return the value of this cell as an instance of type T. /// Overloads exist for most C++ fundamental types like bool, int, etc. as well - /// as for string and xlnt datetime types: date, time, datetime, and timedelta. + /// as for std::string and xlnt datetime types: date, time, datetime, and timedelta. /// template T get_value() const; @@ -135,8 +135,7 @@ public: /// /// Set the value of this cell to the given value. /// Overloads exist for most C++ fundamental types like bool, int, etc. as well - /// as for string and xlnt datetime types: date, time, datetime, and timedelta. - /// + /// as for std::string and xlnt datetime types: date, time, datetime, and timedelta. template void set_value(T value); @@ -195,7 +194,7 @@ public: /// /// Add a hyperlink to this cell pointing to the URI of the given value. /// - void set_hyperlink(const string &value); + void set_hyperlink(const std::string &value); /// /// Return true if this cell has a hyperlink set. @@ -293,8 +292,8 @@ public: bool has_comment() const; // formula - string get_formula() const; - void set_formula(const string &formula); + std::string get_formula() const; + void set_formula(const std::string &formula); void clear_formula(); bool has_formula() const; @@ -303,13 +302,13 @@ public: /// /// Returns a string describing this cell like . /// - string to_repr() const; + std::string to_repr() const; /// /// Returns a string representing the value of this cell. If the data type is not a string, /// it will be converted according to the number format. /// - string to_string() const; + std::string to_string() const; // merging @@ -329,12 +328,12 @@ public: /// /// Return the error string that is stored in this cell. /// - string get_error() const; + std::string get_error() const; /// /// Directly assign the value of this cell to be the given error. /// - void set_error(const string &error); + void set_error(const std::string &error); /// /// Return a cell from this cell's parent workbook at @@ -381,19 +380,13 @@ public: /// /// Return true if this cell is uninitialized. /// - friend XLNT_FUNCTION bool operator==(std::nullptr_t, const cell &cell); + friend bool operator==(std::nullptr_t, const cell &cell); /// /// Return the result of left.get_reference() < right.get_reference(). /// What's the point of this? /// - friend XLNT_FUNCTION bool operator<(const cell left, const cell right); - - /// - /// Convenience function for writing cell to an ostream. - /// Uses cell::to_string() internally. - /// - friend XLNT_FUNCTION std::ostream &operator<<(std::ostream &stream, const xlnt::cell &cell); + friend bool operator<(cell left, cell right); private: // make these friends so they can use the private constructor @@ -412,4 +405,13 @@ private: detail::cell_impl *d_; }; +/// +/// Convenience function for writing cell to an ostream. +/// Uses cell::to_string() internally. +/// +inline std::ostream & XLNT_FUNCTION operator<<(std::ostream &stream, const xlnt::cell &cell) +{ + return stream << cell.to_string(); +} + } // namespace xlnt diff --git a/include/xlnt/cell/cell_reference.hpp b/include/xlnt/cell/cell_reference.hpp index f15b1e4a..7142530d 100644 --- a/include/xlnt/cell/cell_reference.hpp +++ b/include/xlnt/cell/cell_reference.hpp @@ -23,12 +23,12 @@ #pragma once #include +#include #include #include -#include -#include +#include "xlnt_config.hpp" namespace xlnt { @@ -57,7 +57,7 @@ class XLNT_CLASS cell_reference /// /// Split a coordinate string like "A1" into an equivalent pair like {"A", 1}. /// - static std::pair split_reference(const string &reference_string); + static std::pair split_reference(const std::string &reference_string); /// /// Split a coordinate string like "A1" into an equivalent pair like {"A", 1}. @@ -65,7 +65,7 @@ class XLNT_CLASS cell_reference /// if column part or row part are prefixed by a dollar-sign indicating they /// are absolute, otherwise false. /// - static std::pair split_reference(const string &reference_string, bool &absolute_column, + static std::pair split_reference(const std::string &reference_string, bool &absolute_column, bool &absolute_row); // constructors @@ -85,13 +85,13 @@ class XLNT_CLASS cell_reference /// /// Constructs a cell_reference from a string reprenting a cell coordinate (e.g. $B14). /// - cell_reference(const string &reference_string); + cell_reference(const std::string &reference_string); /// /// Constructs a cell_reference from a string reprenting a column (e.g. A) and /// a 1-indexed row. /// - cell_reference(const string &column, row_t row); + cell_reference(const std::string &column, row_t row); /// /// Constructs a cell_reference from a 1-indexed column index and row index. @@ -163,7 +163,7 @@ class XLNT_CLASS cell_reference /// /// Set the column of this reference from a string that identifies a particular column. /// - void set_column(const string &column_string) + void set_column(const std::string &column_string) { column_ = column_t(column_string); } @@ -211,7 +211,7 @@ class XLNT_CLASS cell_reference /// /// Return a string like "A1" for cell_reference(1, 1). /// - string to_string() const; + std::string to_string() const; /// /// Return a 1x1 range_reference containing only this cell_reference. @@ -237,7 +237,7 @@ class XLNT_CLASS cell_reference /// Construct a cell_reference from reference_string and return the result /// of their comparison. /// - bool operator==(const string &reference_string) const + bool operator==(const std::string &reference_string) const { return *this == cell_reference(reference_string); } @@ -248,7 +248,7 @@ class XLNT_CLASS cell_reference /// bool operator==(const char *reference_string) const { - return *this == string(reference_string); + return *this == std::string(reference_string); } /// @@ -264,7 +264,7 @@ class XLNT_CLASS cell_reference /// Construct a cell_reference from reference_string and return the result /// of their comparison. /// - bool operator!=(const string &reference_string) const + bool operator!=(const std::string &reference_string) const { return *this != cell_reference(reference_string); } @@ -275,7 +275,7 @@ class XLNT_CLASS cell_reference /// bool operator!=(const char *reference_string) const { - return *this != string(reference_string); + return *this != std::string(reference_string); } //TODO: are these useful? maybe get rid of them diff --git a/include/xlnt/cell/comment.hpp b/include/xlnt/cell/comment.hpp index 025ba97d..dc3365a1 100644 --- a/include/xlnt/cell/comment.hpp +++ b/include/xlnt/cell/comment.hpp @@ -1,8 +1,8 @@ #pragma once -#include +#include -#include +#include "xlnt_config.hpp" namespace xlnt { @@ -23,19 +23,19 @@ class XLNT_CLASS comment /// /// Constructs a comment applied to the given cell, parent, and with the comment /// text and author set to the provided respective values. - comment(cell parent, const string &text, const string &auth); + comment(cell parent, const std::string &text, const std::string &auth); ~comment(); /// /// Return the text that will be displayed for this comment. /// - string get_text() const; + std::string get_text() const; /// /// Return the author of this comment. /// - string get_author() const; + std::string get_author() const; /// /// True if the comments point to the same sell (false if diff --git a/include/xlnt/cell/types.hpp b/include/xlnt/cell/types.hpp index 39d55642..01aa13b3 100644 --- a/include/xlnt/cell/types.hpp +++ b/include/xlnt/cell/types.hpp @@ -24,10 +24,9 @@ #include #include +#include -#include - -#include +#include "xlnt_config.hpp" // We might want to change these types for various optimizations in the future // so use typedefs. @@ -57,7 +56,7 @@ public: /// restrict our column names to 1 - 3 characters, each in the range A - Z. /// Strings outside this range and malformed strings will throw xlnt::column_string_index_exception. /// - static index_t column_index_from_string(const string &column_string); + static index_t column_index_from_string(const std::string &column_string); /// /// Convert a column number into a column letter (3 -> 'C') @@ -67,7 +66,7 @@ public: /// order. These indices are 1-based, and can be converted to ASCII /// ordinals by adding 64. /// - static string column_string_from_index(index_t column_index); + static std::string column_string_from_index(index_t column_index); /// /// Default column_t is the first (left-most) column. @@ -82,12 +81,12 @@ public: /// /// Construct a column from a string. /// - explicit column_t(const string &column_string) : index(column_index_from_string(column_string)) {} + explicit column_t(const std::string &column_string) : index(column_index_from_string(column_string)) {} /// /// Construct a column from a string. /// - explicit column_t(const char *column_string) : column_t(string(column_string)) {} + explicit column_t(const char *column_string) : column_t(std::string(column_string)) {} /// /// Copy constructor @@ -102,7 +101,7 @@ public: /// /// Return a string representation of this column index. /// - string column_string() const { return column_string_from_index(index); } + std::string column_string() const { return column_string_from_index(index); } /// /// Set this column to be the same as rhs's and return reference to self. @@ -112,7 +111,7 @@ public: /// /// Set this column to be equal to rhs and return reference to self. /// - column_t &operator=(const string &rhs) { return *this = column_t(rhs); } + column_t &operator=(const std::string &rhs) { return *this = column_t(rhs); } /// /// Set this column to be equal to rhs and return reference to self. @@ -142,7 +141,7 @@ public: /// /// Return true if this column refers to the same column as other. /// - bool operator==(const string &other) const { return *this == column_t(other); } + bool operator==(const std::string &other) const { return *this == column_t(other); } /// /// Return true if this column refers to the same column as other. @@ -162,7 +161,7 @@ public: /// /// Return true if this column doesn't refer to the same column as other. /// - bool operator!=(const string &other) const { return !(*this == other); } + bool operator!=(const std::string &other) const { return !(*this == other); } /// /// Return true if this column doesn't refer to the same column as other. diff --git a/include/xlnt/drawing/drawing.hpp b/include/xlnt/drawing/drawing.hpp index ee4a64d1..b2453c96 100644 --- a/include/xlnt/drawing/drawing.hpp +++ b/include/xlnt/drawing/drawing.hpp @@ -23,7 +23,7 @@ // @author: see AUTHORS file #pragma once -#include +#include "xlnt_config.hpp" namespace xlnt { diff --git a/include/xlnt/formula/tokenizer.hpp b/include/xlnt/formula/tokenizer.hpp index f28c0fa9..d064246c 100644 --- a/include/xlnt/formula/tokenizer.hpp +++ b/include/xlnt/formula/tokenizer.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include "xlnt_config.hpp" namespace xlnt { diff --git a/include/xlnt/formula/translator.hpp b/include/xlnt/formula/translator.hpp index 00287814..122ab771 100644 --- a/include/xlnt/formula/translator.hpp +++ b/include/xlnt/formula/translator.hpp @@ -3,7 +3,7 @@ #include #include -#include +#include "xlnt_config.hpp" namespace xlnt { @@ -12,24 +12,24 @@ class tokenizer; class XLNT_CLASS translator { - translator(const string &formula, const cell_reference &ref); + translator(const std::string &formula, const cell_reference &ref); - std::vector get_tokens(); + std::vector get_tokens(); - static string translate_row(const string &row_str, int row_delta); - static string translate_col(const string &col_str, col_delta); + static std::string translate_row(const std::string &row_str, int row_delta); + static std::string translate_col(const std::string &col_str, col_delta); - std::pair strip_ws_name(const string &range_str); + std::pair strip_ws_name(const std::string &range_str); void translate_range(const range_reference &range_ref); void translate_formula(const cell_reference &dest); private: - const string ROW_RANGE_RE; - const string COL_RANGE_RE; - const string CELL_REF_RE; + const std::string ROW_RANGE_RE; + const std::string COL_RANGE_RE; + const std::string CELL_REF_RE; - string formula_; + std::string formula_; cell_reference reference_; tokenizer tokenizer_; }; diff --git a/include/xlnt/packaging/document_properties.hpp b/include/xlnt/packaging/document_properties.hpp index 840e1473..2b1bf484 100644 --- a/include/xlnt/packaging/document_properties.hpp +++ b/include/xlnt/packaging/document_properties.hpp @@ -27,7 +27,7 @@ #include -#include +#include "xlnt_config.hpp" namespace xlnt { @@ -39,16 +39,16 @@ class XLNT_CLASS document_properties public: document_properties(); - string creator; - string last_modified_by; + std::string creator; + std::string last_modified_by; datetime created; datetime modified; - string title = "Untitled"; - string subject; - string description; - string keywords; - string category; - string company; + std::string title = "Untitled"; + std::string subject; + std::string description; + std::string keywords; + std::string category; + std::string company; calendar excel_base_date; }; diff --git a/include/xlnt/packaging/manifest.hpp b/include/xlnt/packaging/manifest.hpp index 1c58ce6f..3ae4db9a 100644 --- a/include/xlnt/packaging/manifest.hpp +++ b/include/xlnt/packaging/manifest.hpp @@ -1,10 +1,9 @@ #pragma once +#include #include -#include - -#include +#include "xlnt_config.hpp" namespace xlnt { @@ -12,51 +11,51 @@ class XLNT_CLASS default_type { public: default_type(); - default_type(const string &extension, const string &content_type); + default_type(const std::string &extension, const std::string &content_type); default_type(const default_type &other); default_type &operator=(const default_type &other); - string get_extension() const + std::string get_extension() const { return extension_; } - string get_content_type() const + std::string get_content_type() const { return content_type_; } private: - string extension_; - string content_type_; + std::string extension_; + std::string content_type_; }; class XLNT_CLASS override_type { public: override_type(); - override_type(const string &extension, const string &content_type); + override_type(const std::string &extension, const std::string &content_type); override_type(const override_type &other); override_type &operator=(const override_type &other); - string get_part_name() const + std::string get_part_name() const { return part_name_; } - string get_content_type() const + std::string get_content_type() const { return content_type_; } private: - string part_name_; - string content_type_; + std::string part_name_; + std::string content_type_; }; class XLNT_CLASS manifest { public: - void add_default_type(const string &extension, const string &content_type); - void add_override_type(const string &part_name, const string &content_type); + void add_default_type(const std::string &extension, const std::string &content_type); + void add_override_type(const std::string &part_name, const std::string &content_type); const std::vector &get_default_types() const { @@ -67,11 +66,11 @@ class XLNT_CLASS manifest return override_types_; } - bool has_default_type(const string &extension) const; - bool has_override_type(const string &part_name) const; + bool has_default_type(const std::string &extension) const; + bool has_override_type(const std::string &part_name) const; - string get_default_type(const string &extension) const; - string get_override_type(const string &part_name) const; + std::string get_default_type(const std::string &extension) const; + std::string get_override_type(const std::string &part_name) const; private: std::vector default_types_; diff --git a/include/xlnt/packaging/relationship.hpp b/include/xlnt/packaging/relationship.hpp index 7e04621a..3e45fe77 100644 --- a/include/xlnt/packaging/relationship.hpp +++ b/include/xlnt/packaging/relationship.hpp @@ -23,7 +23,7 @@ // @author: see AUTHORS file #pragma once -#include +#include namespace xlnt { @@ -46,10 +46,10 @@ enum class target_mode /// Represents an association between a source Package or part, and a target object which can be a part or external /// resource. /// -class XLNT_CLASS relationship +class relationship { public: - enum class XLNT_CLASS type + enum class type { invalid, hyperlink, @@ -65,7 +65,7 @@ class XLNT_CLASS relationship custom_xml }; - static type type_from_string(const string &type_string) + static type type_from_string(const std::string &type_string) { if (type_string == "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties") { @@ -111,7 +111,7 @@ class XLNT_CLASS relationship return type::invalid; } - static string type_to_string(type t) + static std::string type_to_string(type t) { switch (t) { @@ -140,19 +140,17 @@ class XLNT_CLASS relationship } } - relationship(); - - relationship(const string &t, const string &r_id = "", const string &target_uri = "") + relationship(); + relationship(const std::string &t, const std::string &r_id = "", const std::string &target_uri = "") : relationship(type_from_string(t), r_id, target_uri) { } - - relationship(type t, const string &r_id = "", const string &target_uri = ""); + relationship(type t, const std::string &r_id = "", const std::string &target_uri = ""); /// /// gets a string that identifies the relationship. /// - string get_id() const + std::string get_id() const { return id_; } @@ -160,7 +158,7 @@ class XLNT_CLASS relationship /// /// gets the URI of the package or part that owns the relationship. /// - string get_source_uri() const + std::string get_source_uri() const { return source_uri_; } @@ -168,7 +166,7 @@ class XLNT_CLASS relationship /// /// gets a value that indicates whether the target of the relationship is or External to the Package. /// - target_mode get_target_mode() const + target_mode get_target_mode() const { return target_mode_; } @@ -176,35 +174,31 @@ class XLNT_CLASS relationship /// /// gets the URI of the target resource of the relationship. /// - string get_target_uri() const + std::string get_target_uri() const { return target_uri_; } - type get_type() const + type get_type() const { return type_; } - - string get_type_string() const + std::string get_type_string() const { return type_to_string(type_); } - friend XLNT_FUNCTION bool operator==(const relationship &left, const relationship &right) + friend bool operator==(const relationship &left, const relationship &right) { - return left.type_ == right.type_ - && left.id_ == right.id_ - && left.source_uri_ == right.source_uri_ - && left.target_uri_ == right.target_uri_ - && left.target_mode_ == right.target_mode_; + return left.type_ == right.type_ && left.id_ == right.id_ && left.source_uri_ == right.source_uri_ && + left.target_uri_ == right.target_uri_ && left.target_mode_ == right.target_mode_; } private: type type_; - string id_; - string source_uri_; - string target_uri_; + std::string id_; + std::string source_uri_; + std::string target_uri_; target_mode target_mode_; }; diff --git a/include/xlnt/packaging/zip_file.hpp b/include/xlnt/packaging/zip_file.hpp index 441b314b..4b223362 100644 --- a/include/xlnt/packaging/zip_file.hpp +++ b/include/xlnt/packaging/zip_file.hpp @@ -4,11 +4,10 @@ #include #include #include +#include #include -#include - -#include +#include "xlnt_config.hpp" // Note: this comes from https://github.com/tfussell/miniz-cpp @@ -40,9 +39,9 @@ struct XLNT_CLASS zip_info zip_info(); date_time_t date_time; - string filename; - string comment; - string extra; + std::string filename; + std::string comment; + std::string extra; uint16_t create_system; uint16_t create_version; uint16_t extract_version; @@ -64,14 +63,14 @@ class XLNT_CLASS zip_file { public: zip_file(); - zip_file(const string &filename); + zip_file(const std::string &filename); zip_file(const std::vector &bytes); zip_file(std::istream &stream); ~zip_file(); // to/from file - void load(const string &filename); - void save(const string &filename); + void load(const std::string &filename); + void save(const std::string &filename); // to/from byte vector void load(const std::vector &bytes); @@ -83,47 +82,47 @@ class XLNT_CLASS zip_file void reset(); - bool has_file(const string &name); + bool has_file(const std::string &name); bool has_file(const zip_info &name); - zip_info getinfo(const string &name); + zip_info getinfo(const std::string &name); std::vector infolist(); - std::vector namelist(); + std::vector namelist(); - std::ostream &open(const string &name); + std::ostream &open(const std::string &name); std::ostream &open(const zip_info &name); - void extract(const string &name); - void extract(const string &name, const string &path); + void extract(const std::string &name); + void extract(const std::string &name, const std::string &path); void extract(const zip_info &name); - void extract(const zip_info &name, const string &path); + void extract(const zip_info &name, const std::string &path); void extractall(); - void extractall(const string &path); - void extractall(const string &path, const std::vector &members); - void extractall(const string &path, const std::vector &members); + void extractall(const std::string &path); + void extractall(const std::string &path, const std::vector &members); + void extractall(const std::string &path, const std::vector &members); void printdir(); void printdir(std::ostream &stream); - string read(const string &name); - string read(const zip_info &name); + std::string read(const std::string &name); + std::string read(const zip_info &name); - std::pair testzip(); + std::pair testzip(); - void write(const string &filename); - void write(const string &filename, const string &arcname); + void write(const std::string &filename); + void write(const std::string &filename, const std::string &arcname); - void writestr(const string &arcname, const string &bytes); - void writestr(const zip_info &arcname, const string &bytes); + void writestr(const std::string &arcname, const std::string &bytes); + void writestr(const zip_info &arcname, const std::string &bytes); - string get_filename() const + std::string get_filename() const { return filename_; } - string comment; + std::string comment; private: void start_read(); @@ -137,7 +136,7 @@ class XLNT_CLASS zip_file std::unique_ptr archive_; std::vector buffer_; std::stringstream open_stream_; - string filename_; + std::string filename_; }; } // namespace xlnt diff --git a/include/xlnt/serialization/comment_serializer.hpp b/include/xlnt/serialization/comment_serializer.hpp index 83261103..41367007 100644 --- a/include/xlnt/serialization/comment_serializer.hpp +++ b/include/xlnt/serialization/comment_serializer.hpp @@ -28,7 +28,7 @@ #include #include -#include +#include "xlnt_config.hpp" namespace xlnt { diff --git a/include/xlnt/serialization/encoding.hpp b/include/xlnt/serialization/encoding.hpp index 96191d32..62053729 100644 --- a/include/xlnt/serialization/encoding.hpp +++ b/include/xlnt/serialization/encoding.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include "xlnt_config.hpp" namespace xlnt { diff --git a/include/xlnt/serialization/excel_serializer.hpp b/include/xlnt/serialization/excel_serializer.hpp index 892ef717..dec5ff30 100644 --- a/include/xlnt/serialization/excel_serializer.hpp +++ b/include/xlnt/serialization/excel_serializer.hpp @@ -30,7 +30,7 @@ #include -#include +#include "xlnt_config.hpp" namespace xlnt { @@ -46,12 +46,12 @@ class XLNT_CLASS excel_serializer /// /// /// - static const string central_directory_signature(); + static const std::string central_directory_signature(); /// /// /// - static string repair_central_directory(const string &original); + static std::string repair_central_directory(const std::string &original); /// /// Construct an excel_serializer which operates on wb. @@ -62,7 +62,7 @@ class XLNT_CLASS excel_serializer /// Create a ZIP file in memory, load archive from filename, then populate workbook /// with data from archive. /// - bool load_workbook(const string &filename, bool guess_types = false, bool data_only = false); + bool load_workbook(const std::string &filename, bool guess_types = false, bool data_only = false); /// /// Create a ZIP file in memory, load archive from stream, then populate workbook @@ -81,7 +81,7 @@ class XLNT_CLASS excel_serializer /// Create a ZIP file in memory, save workbook to this archive, then save archive /// to filename. /// - bool save_workbook(const string &filename, bool as_template = false); + bool save_workbook(const std::string &filename, bool as_template = false); /// /// Create a ZIP file in memory, save workbook to this archive, then assign ZIP file diff --git a/include/xlnt/serialization/manifest_serializer.hpp b/include/xlnt/serialization/manifest_serializer.hpp index 1377b5b8..7297b634 100644 --- a/include/xlnt/serialization/manifest_serializer.hpp +++ b/include/xlnt/serialization/manifest_serializer.hpp @@ -2,7 +2,7 @@ #include -#include +#include "xlnt_config.hpp" namespace xlnt { @@ -17,7 +17,7 @@ class XLNT_CLASS manifest_serializer void read_manifest(const xml_document &xml); xml_document write_manifest() const; - string determine_document_type() const; + std::string determine_document_type() const; private: manifest &manifest_; diff --git a/include/xlnt/serialization/relationship_serializer.hpp b/include/xlnt/serialization/relationship_serializer.hpp index 08559c99..a2740fe4 100644 --- a/include/xlnt/serialization/relationship_serializer.hpp +++ b/include/xlnt/serialization/relationship_serializer.hpp @@ -1,10 +1,9 @@ #pragma once +#include #include -#include - -#include +#include "xlnt_config.hpp" namespace xlnt { @@ -25,12 +24,12 @@ public: /// /// Return a vector of relationships corresponding to target. /// - std::vector read_relationships(const string &target); + std::vector read_relationships(const std::string &target); /// /// Write relationships to archive for the given target. /// - bool write_relationships(const std::vector &relationships, const string &target); + bool write_relationships(const std::vector &relationships, const std::string &target); private: /// diff --git a/include/xlnt/serialization/shared_strings_serializer.hpp b/include/xlnt/serialization/shared_strings_serializer.hpp index 81456f01..cb14142b 100644 --- a/include/xlnt/serialization/shared_strings_serializer.hpp +++ b/include/xlnt/serialization/shared_strings_serializer.hpp @@ -23,11 +23,10 @@ // @author: see AUTHORS file #pragma once +#include #include -#include - -#include +#include "xlnt_config.hpp" namespace xlnt { @@ -36,8 +35,8 @@ class xml_document; class XLNT_CLASS shared_strings_serializer { public: - static bool read_shared_strings(const xml_document &xml, std::vector &strings); - static xml_document write_shared_strings(const std::vector &strings); + static bool read_shared_strings(const xml_document &xml, std::vector &strings); + static xml_document write_shared_strings(const std::vector &strings); }; } // namespace xlnt diff --git a/include/xlnt/serialization/style_serializer.hpp b/include/xlnt/serialization/style_serializer.hpp index fdf1bbac..8ab5b3dc 100644 --- a/include/xlnt/serialization/style_serializer.hpp +++ b/include/xlnt/serialization/style_serializer.hpp @@ -29,7 +29,7 @@ #include -#include +#include "xlnt_config.hpp" namespace xlnt { @@ -133,7 +133,7 @@ class XLNT_CLASS style_serializer /// /// Read and return a pair containing a name and corresponding style from named_style_node. /// - static std::pair read_named_style(const xml_node &named_style_node); + static std::pair read_named_style(const xml_node &named_style_node); // // Static element writers (i.e. writers that don't use internal state) diff --git a/include/xlnt/serialization/theme_serializer.hpp b/include/xlnt/serialization/theme_serializer.hpp index 3b4d1366..53118823 100644 --- a/include/xlnt/serialization/theme_serializer.hpp +++ b/include/xlnt/serialization/theme_serializer.hpp @@ -25,7 +25,7 @@ #include -#include +#include "xlnt_config.hpp" namespace xlnt { diff --git a/include/xlnt/serialization/workbook_serializer.hpp b/include/xlnt/serialization/workbook_serializer.hpp index a4b41fa7..2e2475f3 100644 --- a/include/xlnt/serialization/workbook_serializer.hpp +++ b/include/xlnt/serialization/workbook_serializer.hpp @@ -26,7 +26,7 @@ #include #include -#include +#include "xlnt_config.hpp" namespace xlnt { @@ -42,7 +42,7 @@ class xml_node; class XLNT_CLASS workbook_serializer { public: - using string_pair = std::pair; + using string_pair = std::pair; workbook_serializer(workbook &wb); diff --git a/include/xlnt/serialization/worksheet_serializer.hpp b/include/xlnt/serialization/worksheet_serializer.hpp index 61082267..35d008a5 100644 --- a/include/xlnt/serialization/worksheet_serializer.hpp +++ b/include/xlnt/serialization/worksheet_serializer.hpp @@ -28,7 +28,7 @@ #include -#include +#include "xlnt_config.hpp" namespace xlnt { diff --git a/include/xlnt/serialization/xml_document.hpp b/include/xlnt/serialization/xml_document.hpp index 3c1e303a..3c9902e6 100644 --- a/include/xlnt/serialization/xml_document.hpp +++ b/include/xlnt/serialization/xml_document.hpp @@ -1,11 +1,10 @@ #pragma once #include +#include #include -#include - -#include +#include "xlnt_config.hpp" namespace xlnt { namespace detail { struct xml_document_impl; } @@ -16,7 +15,7 @@ class xml_serializer; class XLNT_CLASS xml_document { public: - using string_pair = std::pair; + using string_pair = std::pair; xml_document(); xml_document(const xml_document &other); @@ -26,20 +25,20 @@ class XLNT_CLASS xml_document xml_document &operator=(const xml_document &other); xml_document &operator=(xml_document &&other); - void set_encoding(const string &encoding); - void add_namespace(const string &id, const string &uri); + void set_encoding(const std::string &encoding); + void add_namespace(const std::string &id, const std::string &uri); xml_node add_child(const xml_node &child); - xml_node add_child(const string &child_name); + xml_node add_child(const std::string &child_name); xml_node get_root(); const xml_node get_root() const; - xml_node get_child(const string &child_name); - const xml_node get_child(const string &child_name) const; + xml_node get_child(const std::string &child_name); + const xml_node get_child(const std::string &child_name) const; - string to_string() const; - xml_document &from_string(const string &xml_string); + std::string to_string() const; + xml_document &from_string(const std::string &xml_string); private: friend class xml_serializer; diff --git a/include/xlnt/serialization/xml_node.hpp b/include/xlnt/serialization/xml_node.hpp index 3bbbee26..09e54115 100644 --- a/include/xlnt/serialization/xml_node.hpp +++ b/include/xlnt/serialization/xml_node.hpp @@ -1,11 +1,10 @@ #pragma once #include +#include #include -#include - -#include +#include "xlnt_config.hpp" namespace xlnt { namespace detail { struct xml_node_impl; } @@ -15,7 +14,7 @@ class xml_document; class XLNT_CLASS xml_node { public: - using string_pair = std::pair; + using string_pair = std::pair; xml_node(); xml_node(const xml_node &other); @@ -23,26 +22,26 @@ class XLNT_CLASS xml_node xml_node &operator=(const xml_node &other); - string get_name() const; - void set_name(const string &name); + std::string get_name() const; + void set_name(const std::string &name); bool has_text() const; - string get_text() const; - void set_text(const string &text); + std::string get_text() const; + void set_text(const std::string &text); const std::vector get_children() const; - bool has_child(const string &child_name) const; - xml_node get_child(const string &child_name); - const xml_node get_child(const string &child_name) const; + bool has_child(const std::string &child_name) const; + xml_node get_child(const std::string &child_name); + const xml_node get_child(const std::string &child_name) const; xml_node add_child(const xml_node &child); - xml_node add_child(const string &child_name); + xml_node add_child(const std::string &child_name); const std::vector get_attributes() const; - bool has_attribute(const string &attribute_name) const; - string get_attribute(const string &attribute_name) const; - void add_attribute(const string &name, const string &value); + bool has_attribute(const std::string &attribute_name) const; + std::string get_attribute(const std::string &attribute_name) const; + void add_attribute(const std::string &name, const std::string &value); - string to_string() const; + std::string to_string() const; private: friend class xml_document; diff --git a/include/xlnt/serialization/xml_serializer.hpp b/include/xlnt/serialization/xml_serializer.hpp index f281b3d5..80615a57 100644 --- a/include/xlnt/serialization/xml_serializer.hpp +++ b/include/xlnt/serialization/xml_serializer.hpp @@ -1,8 +1,8 @@ #pragma once -#include +#include -#include +#include "xlnt_config.hpp" namespace xlnt { @@ -12,10 +12,10 @@ class xml_node; class XLNT_CLASS xml_serializer { public: - static string serialize(const xml_document &xml); - static xml_document deserialize(const string &xml_string); + static std::string serialize(const xml_document &xml); + static xml_document deserialize(const std::string &xml_string); - static string serialize_node(const xml_node &xml); + static std::string serialize_node(const xml_node &xml); }; } // namespace xlnt diff --git a/include/xlnt/styles/alignment.hpp b/include/xlnt/styles/alignment.hpp index 7b8c9bb1..51f3f4d9 100644 --- a/include/xlnt/styles/alignment.hpp +++ b/include/xlnt/styles/alignment.hpp @@ -25,7 +25,7 @@ #include -#include +#include "xlnt_config.hpp" namespace xlnt { diff --git a/include/xlnt/styles/border.hpp b/include/xlnt/styles/border.hpp index 338f579f..233e2715 100644 --- a/include/xlnt/styles/border.hpp +++ b/include/xlnt/styles/border.hpp @@ -29,7 +29,7 @@ #include #include -#include +#include "xlnt_config.hpp" namespace xlnt { diff --git a/include/xlnt/styles/color.hpp b/include/xlnt/styles/color.hpp index 4beded0f..90d6cbdd 100644 --- a/include/xlnt/styles/color.hpp +++ b/include/xlnt/styles/color.hpp @@ -23,10 +23,11 @@ // @author: see AUTHORS file #pragma once -#include -#include +#include -#include +#include + +#include "xlnt_config.hpp" namespace xlnt { @@ -60,7 +61,7 @@ class XLNT_CLASS color { } - color(type t, const string &v) : type_(t), rgb_string_(v) + color(type t, const std::string &v) : type_(t), rgb_string_(v) { } @@ -117,7 +118,7 @@ class XLNT_CLASS color return index_; } - string get_rgb_string() const + std::string get_rgb_string() const { if (type_ != type::rgb) { @@ -151,7 +152,7 @@ class XLNT_CLASS color private: type type_ = type::indexed; std::size_t index_ = 0; - string rgb_string_; + std::string rgb_string_; }; } // namespace xlnt diff --git a/include/xlnt/styles/fill.hpp b/include/xlnt/styles/fill.hpp index 6ae54b63..8914fbe0 100644 --- a/include/xlnt/styles/fill.hpp +++ b/include/xlnt/styles/fill.hpp @@ -26,7 +26,7 @@ #include #include -#include +#include "xlnt_config.hpp" namespace xlnt { @@ -79,7 +79,7 @@ class XLNT_CLASS fill type_ = t; } - string get_pattern_type_string() const + std::string get_pattern_type_string() const { if (type_ != type::pattern) { @@ -131,7 +131,7 @@ class XLNT_CLASS fill } } - string get_gradient_type_string() const + std::string get_gradient_type_string() const { if (type_ != type::gradient) { diff --git a/include/xlnt/styles/font.hpp b/include/xlnt/styles/font.hpp index 939a81a1..f6dbd483 100644 --- a/include/xlnt/styles/font.hpp +++ b/include/xlnt/styles/font.hpp @@ -28,7 +28,7 @@ #include #include -#include +#include "xlnt_config.hpp" namespace xlnt { @@ -101,11 +101,11 @@ class XLNT_CLASS font return size_; } - void set_name(const string &name) + void set_name(const std::string &name) { name_ = name; } - string get_name() const + std::string get_name() const { return name_; } @@ -121,7 +121,7 @@ class XLNT_CLASS font family_ = family; } - void set_scheme(const string &scheme) + void set_scheme(const std::string &scheme) { has_scheme_ = true; scheme_ = scheme; @@ -174,7 +174,7 @@ class XLNT_CLASS font private: friend class style; - string name_ = "Calibri"; + std::string name_ = "Calibri"; std::size_t size_ = 11; bool bold_ = false; bool italic_ = false; @@ -186,7 +186,7 @@ class XLNT_CLASS font bool has_family_ = false; std::size_t family_; bool has_scheme_ = false; - string scheme_; + std::string scheme_; }; } // namespace xlnt diff --git a/include/xlnt/styles/named_style.hpp b/include/xlnt/styles/named_style.hpp index 8cc8fee7..c108b67c 100644 --- a/include/xlnt/styles/named_style.hpp +++ b/include/xlnt/styles/named_style.hpp @@ -25,7 +25,7 @@ #include -#include +#include "xlnt_config.hpp" namespace xlnt { @@ -42,7 +42,7 @@ class XLNT_CLASS named_style } private: - string name_; + std::string name_; style style_; }; diff --git a/include/xlnt/styles/number_format.hpp b/include/xlnt/styles/number_format.hpp index e1193e48..8c8ea3cd 100644 --- a/include/xlnt/styles/number_format.hpp +++ b/include/xlnt/styles/number_format.hpp @@ -23,12 +23,11 @@ // @author: see AUTHORS file #pragma once +#include #include #include -#include - -#include +#include "xlnt_config.hpp" namespace xlnt { @@ -74,13 +73,13 @@ class XLNT_CLASS number_format number_format(); number_format(std::size_t builtin_id); - number_format(const string &code); - number_format(const string &code, std::size_t custom_id); + number_format(const std::string &code); + number_format(const std::string &code, std::size_t custom_id); - void set_format_string(const string &format_code); - void set_format_string(const string &format_code, std::size_t custom_id); + void set_format_string(const std::string &format_code); + void set_format_string(const std::string &format_code, std::size_t custom_id); - string get_format_string() const; + std::string get_format_string() const; bool has_id() const { @@ -113,7 +112,7 @@ class XLNT_CLASS number_format private: bool id_set_; std::size_t id_; - string format_string_; + std::string format_string_; }; } // namespace xlnt diff --git a/include/xlnt/styles/protection.hpp b/include/xlnt/styles/protection.hpp index b0915265..007b8d08 100644 --- a/include/xlnt/styles/protection.hpp +++ b/include/xlnt/styles/protection.hpp @@ -27,7 +27,7 @@ #include -#include +#include "xlnt_config.hpp" namespace xlnt { diff --git a/include/xlnt/styles/side.hpp b/include/xlnt/styles/side.hpp index 5a3c5437..63cd8ee7 100644 --- a/include/xlnt/styles/side.hpp +++ b/include/xlnt/styles/side.hpp @@ -27,7 +27,7 @@ #include -#include +#include "xlnt_config.hpp" namespace xlnt { diff --git a/include/xlnt/styles/style.hpp b/include/xlnt/styles/style.hpp index cf69e8ee..f2e43868 100644 --- a/include/xlnt/styles/style.hpp +++ b/include/xlnt/styles/style.hpp @@ -30,7 +30,7 @@ #include #include -#include +#include "xlnt_config.hpp" namespace xlnt { diff --git a/include/xlnt/utils/datetime.hpp b/include/xlnt/utils/datetime.hpp index 3cd0b032..cb090fb1 100644 --- a/include/xlnt/utils/datetime.hpp +++ b/include/xlnt/utils/datetime.hpp @@ -22,9 +22,9 @@ // @author: see AUTHORS file #pragma once -#include +#include -#include +#include "xlnt_config.hpp" namespace xlnt { @@ -98,8 +98,7 @@ struct XLNT_CLASS time : hour(hour_), minute(minute_), second(second_), microsecond(microsecond_) { } - - explicit time(const string &time_string); + explicit time(const std::string &time_string); long double to_number() const; bool operator==(const time &comparand) const; @@ -144,7 +143,7 @@ struct XLNT_CLASS datetime { } - string to_string(calendar base_date) const; + std::string to_string(calendar base_date) const; long double to_number(calendar base_date) const; bool operator==(const datetime &comparand) const; diff --git a/include/xlnt/utils/exceptions.hpp b/include/xlnt/utils/exceptions.hpp index 48663e7f..6166291d 100644 --- a/include/xlnt/utils/exceptions.hpp +++ b/include/xlnt/utils/exceptions.hpp @@ -27,34 +27,34 @@ #include -#include +#include "xlnt_config.hpp" namespace xlnt { /// /// Error for converting between numeric and A1-style cell references. /// -class XLNT_CLASS cell_coordinates_exception +class XLNT_CLASS cell_coordinates_exception : public std::runtime_error { public: cell_coordinates_exception(column_t column, row_t row); - cell_coordinates_exception(const string &coord_string); + cell_coordinates_exception(const std::string &coord_string); }; /// /// The data submitted which cannot be used directly in Excel files. It /// must be removed or escaped. /// -class XLNT_CLASS illegal_character_error +class XLNT_CLASS illegal_character_error : public std::runtime_error { public: - illegal_character_error(utf32_char c); + illegal_character_error(char c); }; /// /// Error for bad column names in A1-style cell references. /// -class XLNT_CLASS column_string_index_exception +class XLNT_CLASS column_string_index_exception : public std::runtime_error { public: column_string_index_exception(); @@ -63,7 +63,7 @@ class XLNT_CLASS column_string_index_exception /// /// Error for any data type inconsistencies. /// -class XLNT_CLASS data_type_exception +class XLNT_CLASS data_type_exception : public std::runtime_error { public: data_type_exception(); @@ -72,7 +72,7 @@ class XLNT_CLASS data_type_exception /// /// Error for badly formatted named ranges. /// -class XLNT_CLASS named_range_exception +class XLNT_CLASS named_range_exception : public std::runtime_error { public: named_range_exception(); @@ -81,25 +81,25 @@ class XLNT_CLASS named_range_exception /// /// Error for bad sheet names. /// -class XLNT_CLASS sheet_title_exception +class XLNT_CLASS sheet_title_exception : public std::runtime_error { public: - sheet_title_exception(const string &title); + sheet_title_exception(const std::string &title); }; /// /// Error for trying to open a non-ooxml file. /// -class XLNT_CLASS invalid_file_exception +class XLNT_CLASS invalid_file_exception : public std::runtime_error { public: - invalid_file_exception(const string &filename); + invalid_file_exception(const std::string &filename); }; /// /// Error for trying to modify a read-only workbook. /// -class XLNT_CLASS read_only_workbook_exception +class XLNT_CLASS read_only_workbook_exception : public std::runtime_error { public: read_only_workbook_exception(); @@ -108,7 +108,7 @@ class XLNT_CLASS read_only_workbook_exception /// /// Error when a references number format is not in the stylesheet. /// -class XLNT_CLASS missing_number_format +class XLNT_CLASS missing_number_format : public std::runtime_error { public: missing_number_format(); @@ -117,16 +117,16 @@ class XLNT_CLASS missing_number_format /// /// Error when an attribute value is invalid. /// -class XLNT_CLASS attribute_error +class XLNT_CLASS attribute_error : public std::runtime_error { public: attribute_error(); }; -class XLNT_CLASS value_error +class XLNT_CLASS value_error : public std::runtime_error { public: - value_error() + value_error() : std::runtime_error("") { } }; diff --git a/include/xlnt/utils/hash_combine.hpp b/include/xlnt/utils/hash_combine.hpp index 077d1641..ce7579a7 100644 --- a/include/xlnt/utils/hash_combine.hpp +++ b/include/xlnt/utils/hash_combine.hpp @@ -2,7 +2,7 @@ #include -#include +#include "xlnt_config.hpp" namespace xlnt { diff --git a/include/xlnt/utils/string.hpp b/include/xlnt/utils/string.hpp deleted file mode 100644 index 7fcddeee..00000000 --- a/include/xlnt/utils/string.hpp +++ /dev/null @@ -1,317 +0,0 @@ -#pragma once - -#include -#include -#include -#include - -#ifdef XLNT_STD_STRING -#include -#endif - -#include - -namespace xlnt { - -template -class iter_range -{ -public: - iter_range(T begin_iter, T end_iter) : begin_(begin_iter), end_(end_iter) - { - } - - T begin() { return begin_; } - T end() { return end_; } - -private: - T begin_; - T end_; -}; - -using utf_mb_narrow_char = char; -using utf_mb_narrow_string = utf_mb_narrow_char[]; -using utf_mb_wide_char = wchar_t; -using utf_mb_wide_string = utf_mb_wide_char[]; -using utf8_char = char; -using utf8_string = utf8_char[]; -using utf16_char = char16_t; -using utf16_string = utf16_char[]; -using utf32_char = char32_t; -using utf32_string = utf32_char[]; - -class XLNT_CLASS string -{ -public: - using code_point = utf32_char; - using reference = code_point &; - using const_reference = const code_point &; - using pointer = code_point *; - using const_pointer = const code_point *; - using byte = char; - using byte_pointer = byte *; - using const_byte_pointer = const byte *; - using difference_type = std::ptrdiff_t; - using size_type = std::size_t; - - class const_iterator; - - class iterator : public std::iterator - { - public: - iterator(string *parent, size_type index); - - iterator(const iterator &other); - - code_point operator*(); - - bool operator==(const iterator &other) const; - - bool operator!=(const iterator &other) const { return !(*this == other); } - - difference_type operator-(const iterator &other) const; - - iterator &operator+=(int offset) { return *this = *this + offset; } - - iterator &operator-=(int offset) { return *this = *this - offset; } - - iterator operator+(int offset); - - iterator operator-(int offset) { return *this + (-1 * offset); } - - iterator &operator--(); - - iterator operator--(int) - { - iterator old = *this; - --*this; - - return old; - } - - iterator &operator++(); - - iterator operator++(int) - { - iterator old = *this; - ++*this; - - return old; - } - - private: - friend class const_iterator; - - string *parent_; - size_type index_; - }; - - class const_iterator : public std::iterator - { - public: - const_iterator(const string *parent, size_type index); - - const_iterator(const string::iterator &other); - - const_iterator(const const_iterator &other); - - const code_point operator*() const; - - bool operator==(const const_iterator &other) const; - - bool operator!=(const const_iterator &other) const { return !(*this == other); } - - difference_type operator-(const const_iterator &other) const; - - const_iterator &operator+=(int offset); - - const_iterator &operator-=(int offset) { return *this += -offset; } - - const_iterator operator+(int offset); - - const_iterator operator-(int offset) { return *this + (-1 * offset); } - - const_iterator &operator--(); - - const_iterator operator--(int) - { - const_iterator old = *this; - --*this; - - return old; - } - - const_iterator &operator++(); - - const_iterator operator++(int) - { - const_iterator old = *this; - ++*this; - - return old; - } - - private: - const string *parent_; - size_type index_; - }; - - using reverse_iterator = std::reverse_iterator; - using const_reverse_iterator = std::reverse_iterator; - - static const size_type npos = -1; - - template - static string from(T value); - - string(); - string(string &&str); - string(const string &str); - string(const string &str, size_type offset); - string(const string &str, size_type offset, size_type len); - -#ifdef XLNT_STD_STRING - string(const std::string &str); -#endif - - string(const utf_mb_wide_string str); - string(const utf8_string str); - string(const utf16_string str); - string(const utf32_string str); - - template - string(InputIterator first, InputIterator last) : string() - { - while (first != last) - { - append(*first); - ++first; - } - } - - ~string(); - - size_type length() const; - size_type num_bytes() const; - - bool empty() const { return length() == 0; } - - string to_upper() const; - string to_lower() const; - - string substr(size_type offset) const; - string substr(size_type offset, size_type len) const; - - code_point back() const; - code_point front() const; - - size_type find(char c) const; - size_type find(code_point c) const; - size_type find(const string &str) const; - - size_type find(char c, size_type offset) const; - size_type find(code_point c, size_type offset) const; - size_type find(const string &str, size_type offset) const; - - size_type find_last_of(char c) const; - size_type find_last_of(code_point c) const; - size_type find_last_of(const string &str) const; - - size_type find_last_of(char c, size_type offset) const; - size_type find_last_of(code_point c, size_type offset) const; - size_type find_last_of(const string &str, size_type offset) const; - - size_type find_first_of(const string &str) const; - size_type find_first_of(const string &str, size_type offset) const; - - size_type find_first_not_of(const string &str) const; - size_type find_first_not_of(const string &str, size_type offset) const; - - size_type find_last_not_of(const string &str) const; - size_type find_last_not_of(const string &str, size_type offset) const; - - void clear(); - - template - T to() const; - - int to_hex() const; - - void erase(size_type index); - - iterator begin(); - const_iterator begin() const { return cbegin(); } - const_iterator cbegin() const; - iterator end(); - const_iterator end() const { return cend(); } - const_iterator cend() const; - - byte_pointer data(); - const_byte_pointer data() const; - - std::size_t hash() const; - - string &operator=(string rhs); - - void append(utf_mb_narrow_char c); - void append(utf_mb_wide_char c); - void append(utf16_char c); - void append(code_point c); - void append(const string &str); - - void replace(size_type index, utf32_char c); - - code_point at(size_type index); - const code_point at(size_type index) const; - - bool operator==(const_byte_pointer str) const; - bool operator!=(const_byte_pointer str) const { return !(*this == str); } - - bool operator==(const string &str) const; - bool operator!=(const string &str) const { return !(*this == str); } - - code_point operator[](size_type index); - const code_point operator[](size_type index) const; - - string operator+(const string &rhs) const; - string &operator+=(const string &rhs); - - bool operator<(const string &other) const; - - friend XLNT_FUNCTION void swap(string &left, string &right); - friend XLNT_FUNCTION std::ostream & operator<<(std::ostream &left, string &right); - friend XLNT_FUNCTION string operator+(const char *left, const string &right); - - friend XLNT_FUNCTION bool operator==(const char *left, const string &right) { return right == left; } - friend XLNT_FUNCTION bool operator!=(const char *left, const string &right) { return right != left; } - -private: - explicit string(size_type initial_size); - - std::vector *data_; - std::unordered_map *code_point_byte_offsets_; -}; - -} // namespace xlnt - -namespace std { - -template<> -struct hash -{ - std::size_t operator()(const xlnt::string &str) const - { - return str.hash(); - } -}; - -template<> -struct less -{ - std::size_t operator()(const xlnt::string &left, const xlnt::string &right) const - { - return left < right; - } -}; - -} // namespace std diff --git a/include/xlnt/workbook/document_security.hpp b/include/xlnt/workbook/document_security.hpp index dfc91d68..c668367c 100644 --- a/include/xlnt/workbook/document_security.hpp +++ b/include/xlnt/workbook/document_security.hpp @@ -25,7 +25,7 @@ #include -#include +#include "xlnt_config.hpp" namespace xlnt { @@ -40,8 +40,8 @@ class XLNT_CLASS document_security bool lock_revision; bool lock_structure; bool lock_windows; - string revision_password; - string workbook_password; + std::string revision_password; + std::string workbook_password; }; } // namespace xlnt diff --git a/include/xlnt/workbook/external_book.hpp b/include/xlnt/workbook/external_book.hpp index e3a49de6..f0d4e20e 100644 --- a/include/xlnt/workbook/external_book.hpp +++ b/include/xlnt/workbook/external_book.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include "xlnt_config.hpp" namespace xlnt { diff --git a/include/xlnt/workbook/named_range.hpp b/include/xlnt/workbook/named_range.hpp index 55c9d893..18e8d067 100644 --- a/include/xlnt/workbook/named_range.hpp +++ b/include/xlnt/workbook/named_range.hpp @@ -3,14 +3,14 @@ #include #include -#include +#include "xlnt_config.hpp" namespace xlnt { class range_reference; class worksheet; -std::vector> XLNT_FUNCTION split_named_range(const string &named_range_string); +std::vector> XLNT_FUNCTION split_named_range(const std::string &named_range_string); class XLNT_CLASS named_range { @@ -19,9 +19,9 @@ class XLNT_CLASS named_range named_range(); named_range(const named_range &other); - named_range(const string &name, const std::vector &targets); + named_range(const std::string &name, const std::vector &targets); - string get_name() const + std::string get_name() const { return name_; } @@ -33,7 +33,7 @@ class XLNT_CLASS named_range named_range &operator=(const named_range &other); private: - string name_; + std::string name_; std::vector targets_; }; } diff --git a/include/xlnt/workbook/theme.hpp b/include/xlnt/workbook/theme.hpp index 1fd2cf24..4fd5dbad 100644 --- a/include/xlnt/workbook/theme.hpp +++ b/include/xlnt/workbook/theme.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include "xlnt_config.hpp" namespace xlnt { diff --git a/include/xlnt/workbook/workbook.hpp b/include/xlnt/workbook/workbook.hpp index 45c4cc1d..f636604b 100644 --- a/include/xlnt/workbook/workbook.hpp +++ b/include/xlnt/workbook/workbook.hpp @@ -31,7 +31,7 @@ #include -#include +#include "xlnt_config.hpp" namespace xlnt { @@ -65,7 +65,7 @@ namespace detail { struct workbook_impl; } // namespace detail class XLNT_CLASS workbook { public: - class XLNT_CLASS iterator + class iterator { public: iterator(workbook &wb, std::size_t index); @@ -85,7 +85,7 @@ class XLNT_CLASS workbook std::size_t index_; }; - class XLNT_CLASS const_iterator + class const_iterator { public: const_iterator(const workbook &wb, std::size_t index); @@ -105,7 +105,7 @@ class XLNT_CLASS workbook std::size_t index_; }; - static std::size_t index_from_ws_filename(const string &filename); + static std::size_t index_from_ws_filename(const std::string &filename); // constructors workbook(); @@ -128,9 +128,9 @@ class XLNT_CLASS workbook // create worksheet create_sheet(); worksheet create_sheet(std::size_t index); - worksheet create_sheet(const string &title); - worksheet create_sheet(std::size_t index, const string &title); - worksheet create_sheet(const string &title, const relationship &rel); + worksheet create_sheet(const std::string &title); + worksheet create_sheet(std::size_t index, const std::string &title); + worksheet create_sheet(const std::string &title, const relationship &rel); // add void add_sheet(worksheet worksheet); @@ -141,14 +141,14 @@ class XLNT_CLASS workbook void clear(); // container operations - worksheet get_sheet_by_name(const string &sheet_name); - const worksheet get_sheet_by_name(const string &sheet_name) const; + worksheet get_sheet_by_name(const std::string &sheet_name); + const worksheet get_sheet_by_name(const std::string &sheet_name) const; worksheet get_sheet_by_index(std::size_t index); const worksheet get_sheet_by_index(std::size_t index) const; - bool contains(const string &key) const; + bool contains(const std::string &key) const; int get_index(worksheet worksheet); - worksheet operator[](const string &name); + worksheet operator[](const std::string &name); worksheet operator[](std::size_t index); iterator begin(); @@ -166,24 +166,23 @@ class XLNT_CLASS workbook const_iterator cbegin() const; const_iterator cend() const; - std::vector get_sheet_names() const; + std::vector get_sheet_names() const; document_properties &get_properties(); const document_properties &get_properties() const; // named ranges std::vector get_named_ranges() const; - void create_named_range(const string &name, worksheet worksheet, const range_reference &reference); - void create_named_range(const string &name, worksheet worksheet, const string &reference_string); - bool has_named_range(const string &name) const; - range get_named_range(const string &name); - void remove_named_range(const string &name); + void create_named_range(const std::string &name, worksheet worksheet, const range_reference &reference); + bool has_named_range(const std::string &name) const; + range get_named_range(const std::string &name); + void remove_named_range(const std::string &name); // serialization bool save(std::vector &data); - bool save(const string &filename); + bool save(const std::string &filename); bool load(const std::vector &data); - bool load(const string &filename); + bool load(const std::string &filename); bool load(std::istream &stream); bool load(zip_file &archive); @@ -201,8 +200,8 @@ class XLNT_CLASS workbook return !(*this == std::nullptr_t{}); } - void create_relationship(const string &id, const string &target, relationship::type type); - relationship get_relationship(const string &id) const; + void create_relationship(const std::string &id, const std::string &target, relationship::type type); + relationship get_relationship(const std::string &id) const; const std::vector &get_relationships() const; void add_alignment(const alignment &a); @@ -239,7 +238,7 @@ class XLNT_CLASS workbook bool get_pivot_button(std::size_t style_id) const; bool get_quote_prefix(std::size_t style_id) const; - void set_code_name(const string &code_name); + void set_code_name(const std::string &code_name); bool has_loaded_theme() const; const theme &get_loaded_theme() const; @@ -252,9 +251,9 @@ class XLNT_CLASS workbook const std::vector &get_root_relationships() const; - void add_shared_string(const string &shared); - std::vector &get_shared_strings(); - const std::vector &get_shared_strings() const; + void add_shared_string(const std::string &shared); + std::vector &get_shared_strings(); + const std::vector &get_shared_strings() const; private: friend class worksheet; diff --git a/include/xlnt/worksheet/cell_vector.hpp b/include/xlnt/worksheet/cell_vector.hpp index c7eb183e..df7621cd 100644 --- a/include/xlnt/worksheet/cell_vector.hpp +++ b/include/xlnt/worksheet/cell_vector.hpp @@ -7,7 +7,7 @@ #include #include -#include +#include "xlnt_config.hpp" namespace xlnt { @@ -18,7 +18,7 @@ class XLNT_CLASS cell_vector { public: template - class XLNT_CLASS common_iterator : public std::iterator + class common_iterator : public std::iterator { public: common_iterator(worksheet ws, const cell_reference &start_cell, major_order order = major_order::row) diff --git a/include/xlnt/worksheet/column_properties.hpp b/include/xlnt/worksheet/column_properties.hpp index 9bea3495..70cc1fee 100644 --- a/include/xlnt/worksheet/column_properties.hpp +++ b/include/xlnt/worksheet/column_properties.hpp @@ -23,7 +23,7 @@ // @author: see AUTHORS file #pragma once -#include +#include "xlnt_config.hpp" namespace xlnt { diff --git a/include/xlnt/worksheet/major_order.hpp b/include/xlnt/worksheet/major_order.hpp index fb28bbda..8eaf04fa 100644 --- a/include/xlnt/worksheet/major_order.hpp +++ b/include/xlnt/worksheet/major_order.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include "xlnt_config.hpp" namespace xlnt { diff --git a/include/xlnt/worksheet/page_margins.hpp b/include/xlnt/worksheet/page_margins.hpp index 100eb294..f4277180 100644 --- a/include/xlnt/worksheet/page_margins.hpp +++ b/include/xlnt/worksheet/page_margins.hpp @@ -23,7 +23,7 @@ // @author: see AUTHORS file #pragma once -#include +#include "xlnt_config.hpp" namespace xlnt { diff --git a/include/xlnt/worksheet/page_setup.hpp b/include/xlnt/worksheet/page_setup.hpp index 4e769734..cc80b986 100644 --- a/include/xlnt/worksheet/page_setup.hpp +++ b/include/xlnt/worksheet/page_setup.hpp @@ -23,7 +23,7 @@ // @author: see AUTHORS file #pragma once -#include +#include "xlnt_config.hpp" namespace xlnt { diff --git a/include/xlnt/worksheet/pane.hpp b/include/xlnt/worksheet/pane.hpp index 3afb7078..544b5e1c 100644 --- a/include/xlnt/worksheet/pane.hpp +++ b/include/xlnt/worksheet/pane.hpp @@ -22,7 +22,7 @@ // @author: see AUTHORS file #pragma once -#include +#include "xlnt_config.hpp" namespace xlnt { diff --git a/include/xlnt/worksheet/range.hpp b/include/xlnt/worksheet/range.hpp index ff47041c..6011b61e 100644 --- a/include/xlnt/worksheet/range.hpp +++ b/include/xlnt/worksheet/range.hpp @@ -32,7 +32,7 @@ #include #include -#include +#include "xlnt_config.hpp" namespace xlnt { @@ -40,7 +40,7 @@ class XLNT_CLASS range { public: template - class XLNT_CLASS common_iterator : public std::iterator + class common_iterator : public std::iterator { public: common_iterator(worksheet ws, const range_reference &start_cell, major_order order = major_order::row) diff --git a/include/xlnt/worksheet/range_reference.hpp b/include/xlnt/worksheet/range_reference.hpp index e58df02a..0c0acd4b 100644 --- a/include/xlnt/worksheet/range_reference.hpp +++ b/include/xlnt/worksheet/range_reference.hpp @@ -24,7 +24,7 @@ #include -#include +#include "xlnt_config.hpp" namespace xlnt { @@ -37,9 +37,9 @@ class XLNT_CLASS range_reference static range_reference make_absolute(const range_reference &relative_reference); range_reference(); - explicit range_reference(const string &range_string); - explicit range_reference(const char *range_string); - explicit range_reference(const std::pair &reference_pair); + range_reference(const std::string &range_string); + range_reference(const char *range_string); + range_reference(const std::pair &reference_pair); range_reference(const cell_reference &start, const cell_reference &end); range_reference(column_t column_index_start, row_t row_index_start, column_t column_index_end, row_t row_index_end); @@ -68,30 +68,25 @@ class XLNT_CLASS range_reference range_reference make_offset(int column_offset, int row_offset) const; - string to_string() const; + std::string to_string() const; bool operator==(const range_reference &comparand) const; - - bool operator==(const string &reference_string) const + bool operator==(const std::string &reference_string) const { return *this == range_reference(reference_string); } - bool operator==(const char *reference_string) const { - return *this == string(reference_string); + return *this == std::string(reference_string); } - bool operator!=(const range_reference &comparand) const; - - bool operator!=(const string &reference_string) const + bool operator!=(const std::string &reference_string) const { return *this != range_reference(reference_string); } - bool operator!=(const char *reference_string) const { - return *this != string(reference_string); + return *this != std::string(reference_string); } private: @@ -99,7 +94,7 @@ class XLNT_CLASS range_reference cell_reference bottom_right_; }; -inline bool XLNT_FUNCTION operator==(const string &reference_string, const range_reference &ref) +inline bool XLNT_FUNCTION operator==(const std::string &reference_string, const range_reference &ref) { return ref == reference_string; } @@ -109,7 +104,7 @@ inline bool XLNT_FUNCTION operator==(const char *reference_string, const range_r return ref == reference_string; } -inline bool XLNT_FUNCTION operator!=(const string &reference_string, const range_reference &ref) +inline bool XLNT_FUNCTION operator!=(const std::string &reference_string, const range_reference &ref) { return ref != reference_string; } diff --git a/include/xlnt/worksheet/row_properties.hpp b/include/xlnt/worksheet/row_properties.hpp index 5771ba06..619526f3 100644 --- a/include/xlnt/worksheet/row_properties.hpp +++ b/include/xlnt/worksheet/row_properties.hpp @@ -23,7 +23,7 @@ // @author: see AUTHORS file #pragma once -#include +#include "xlnt_config.hpp" namespace xlnt { diff --git a/include/xlnt/worksheet/selection.hpp b/include/xlnt/worksheet/selection.hpp index bc403778..736dc943 100644 --- a/include/xlnt/worksheet/selection.hpp +++ b/include/xlnt/worksheet/selection.hpp @@ -22,7 +22,7 @@ // @author: see AUTHORS file #pragma once -#include +#include "xlnt_config.hpp" namespace xlnt { diff --git a/include/xlnt/worksheet/sheet_protection.hpp b/include/xlnt/worksheet/sheet_protection.hpp index b8ad2f5f..3ea0b073 100644 --- a/include/xlnt/worksheet/sheet_protection.hpp +++ b/include/xlnt/worksheet/sheet_protection.hpp @@ -1,24 +1,24 @@ #pragma once -#include +#include -#include +#include "xlnt_config.hpp" namespace xlnt { class XLNT_CLASS sheet_protection { public: - static string hash_password(const string &password); + static std::string hash_password(const std::string &password); - void set_password(const string &password); - string get_hashed_password() const + void set_password(const std::string &password); + std::string get_hashed_password() const { return hashed_password_; } private: - string hashed_password_; + std::string hashed_password_; }; } // namespace xlnt diff --git a/include/xlnt/worksheet/sheet_view.hpp b/include/xlnt/worksheet/sheet_view.hpp index 20ea6f5b..a17d2b7a 100644 --- a/include/xlnt/worksheet/sheet_view.hpp +++ b/include/xlnt/worksheet/sheet_view.hpp @@ -22,7 +22,7 @@ // @author: see AUTHORS file #pragma once -#include +#include "xlnt_config.hpp" namespace xlnt { diff --git a/include/xlnt/worksheet/worksheet.hpp b/include/xlnt/worksheet/worksheet.hpp index 97d6d162..d7ab7556 100644 --- a/include/xlnt/worksheet/worksheet.hpp +++ b/include/xlnt/worksheet/worksheet.hpp @@ -33,7 +33,7 @@ #include #include -#include +#include "xlnt_config.hpp" namespace xlnt { @@ -58,12 +58,12 @@ class XLNT_CLASS header { public: header(); - void set_text(const string &text) + void set_text(const std::string &text) { default_ = false; text_ = text; } - void set_font_name(const string &font_name) + void set_font_name(const std::string &font_name) { default_ = false; font_name_ = font_name; @@ -73,7 +73,7 @@ class XLNT_CLASS header default_ = false; font_size_ = font_size; } - void set_font_color(const string &font_color) + void set_font_color(const std::string &font_color) { default_ = false; font_color_ = font_color; @@ -85,10 +85,10 @@ class XLNT_CLASS header private: bool default_; - string text_; - string font_name_; + std::string text_; + std::string font_name_; std::size_t font_size_; - string font_color_; + std::string font_color_; }; /// @@ -98,12 +98,12 @@ class XLNT_CLASS footer { public: footer(); - void set_text(const string &text) + void set_text(const std::string &text) { default_ = false; text_ = text; } - void set_font_name(const string &font_name) + void set_font_name(const std::string &font_name) { default_ = false; font_name_ = font_name; @@ -113,7 +113,7 @@ class XLNT_CLASS footer default_ = false; font_size_ = font_size; } - void set_font_color(const string &font_color) + void set_font_color(const std::string &font_color) { default_ = false; font_color_ = font_color; @@ -125,10 +125,10 @@ class XLNT_CLASS footer private: bool default_; - string text_; - string font_name_; + std::string text_; + std::string font_name_; std::size_t font_size_; - string font_color_; + std::string font_color_; }; /// @@ -269,21 +269,21 @@ class XLNT_CLASS worksheet public: worksheet(); worksheet(const worksheet &rhs); - worksheet(workbook &parent_workbook, const string &title = string()); + worksheet(workbook &parent_workbook, const std::string &title = std::string()); - string to_string() const; + std::string to_string() const; workbook &get_parent() const; void garbage_collect(); // title - string get_title() const; - void set_title(const string &title); - string make_unique_sheet_name(const string &value); + std::string get_title() const; + void set_title(const std::string &title); + std::string make_unique_sheet_name(const std::string &value); // freeze panes cell_reference get_frozen_panes() const; void freeze_panes(cell top_left_cell); - void freeze_panes(const string &top_left_coordinate); + void freeze_panes(const std::string &top_left_coordinate); void unfreeze_panes(); bool has_frozen_panes() const; @@ -292,14 +292,12 @@ class XLNT_CLASS worksheet const cell get_cell(const cell_reference &reference) const; range get_range(const range_reference &reference); const range get_range(const range_reference &reference) const; - range get_range(const string &reference_string); - const range get_range(const string &reference_string) const; range get_squared_range(column_t min_col, row_t min_row, column_t max_col, row_t max_row); const range get_squared_range(column_t min_col, row_t min_row, column_t max_col, row_t max_row) const; range rows() const; - range rows(const string &range_string) const; + range rows(const std::string &range_string) const; range rows(int row_offset, int column_offset) const; - range rows(const string &range_string, int row_offset, int column_offset) const; + range rows(const std::string &range_string, int row_offset, int column_offset) const; range columns() const; std::list get_cell_collection(); @@ -318,13 +316,13 @@ class XLNT_CLASS worksheet cell_reference get_point_pos(int left, int top) const; cell_reference get_point_pos(const std::pair &point) const; - string unique_sheet_name(const string &value) const; + std::string unique_sheet_name(const std::string &value) const; // named range - void create_named_range(const string &name, const range_reference &reference); - bool has_named_range(const string &name); - range get_named_range(const string &name); - void remove_named_range(const string &name); + void create_named_range(const std::string &name, const range_reference &reference); + bool has_named_range(const std::string &name); + range get_named_range(const std::string &name); + void remove_named_range(const std::string &name); // extents row_t get_lowest_row() const; @@ -335,7 +333,7 @@ class XLNT_CLASS worksheet range_reference calculate_dimension() const; // relationships - relationship create_relationship(relationship::type type, const string &target_uri); + relationship create_relationship(relationship::type type, const std::string &target_uri); const std::vector &get_relationships() const; // charts @@ -343,21 +341,19 @@ class XLNT_CLASS worksheet // cell merge void merge_cells(const range_reference &reference); - void merge_cells(const string &reference_string); void merge_cells(column_t start_column, row_t start_row, column_t end_column, row_t end_row); void unmerge_cells(const range_reference &reference); - void unmerge_cells(const string &reference_string); void unmerge_cells(column_t start_column, row_t start_row, column_t end_column, row_t end_row); std::vector get_merged_ranges() const; // append void append(); - void append(const std::vector &cells); + void append(const std::vector &cells); void append(const std::vector &cells); void append(const std::vector &cells); void append(const std::vector &cells); - void append(const std::unordered_map &cells); - void append(const std::unordered_map &cells); + void append(const std::unordered_map &cells); + void append(const std::unordered_map &cells); void append(const std::vector::const_iterator begin, const std::vector::const_iterator end); @@ -371,8 +367,8 @@ class XLNT_CLASS worksheet const cell operator[](const cell_reference &reference) const; range operator[](const range_reference &reference); const range operator[](const range_reference &reference) const; - range operator[](const string &range_string); - const range operator[](const string &range_string) const; + range operator[](const std::string &range_string); + const range operator[](const std::string &range_string) const; range operator()(const cell_reference &top_left, const cell_reference &bottom_right); const range operator()(const cell_reference &top_left, const cell_reference &bottom_right) const; @@ -386,7 +382,6 @@ class XLNT_CLASS worksheet range_reference get_auto_filter() const; void auto_filter(const xlnt::range &range); void auto_filter(const range_reference &reference); - void auto_filter(const string &reference_string); void unset_auto_filter(); bool has_auto_filter() const; @@ -402,7 +397,7 @@ class XLNT_CLASS worksheet void set_parent(workbook &wb); - std::vector get_formula_attributes() const; + std::vector get_formula_attributes() const; void set_sheet_state(page_setup::sheet_state state); diff --git a/include/xlnt/worksheet/worksheet_properties.hpp b/include/xlnt/worksheet/worksheet_properties.hpp index 26fe501b..bca58299 100644 --- a/include/xlnt/worksheet/worksheet_properties.hpp +++ b/include/xlnt/worksheet/worksheet_properties.hpp @@ -23,7 +23,7 @@ // @author: see AUTHORS file #pragma once -#include +#include "xlnt_config.hpp" namespace xlnt { diff --git a/include/xlnt/xlnt.hpp b/include/xlnt/xlnt.hpp index 549b179f..2f990c3c 100644 --- a/include/xlnt/xlnt.hpp +++ b/include/xlnt/xlnt.hpp @@ -25,7 +25,7 @@ #include -#include +#include "xlnt_config.hpp" #include #include diff --git a/include/xlnt/xlnt_config.hpp b/include/xlnt/xlnt_config.hpp index e910f48a..ee53f807 100644 --- a/include/xlnt/xlnt_config.hpp +++ b/include/xlnt/xlnt_config.hpp @@ -54,27 +54,18 @@ enum class limit_style /// const limit_style LimitStyle = limit_style::openpyxl; +// If no API is defined, assume default #ifndef XLNT_API #ifdef _MSC_VER -#ifdef XLNT_SHARED -#ifdef XLNT_EXPORT +#ifdef _DLL #define XLNT_API __declspec(dllexport) #else #define XLNT_API __declspec(dllimport) -#endif // XLNT_EXPORT +#endif #else #define XLNT_API -#endif // XLNT_SHARED -#else -#define XLNT_API -#endif // _MSC_VER -#endif // XLNT_API - -#ifndef XLNT_STD_STRING -#ifndef XLNT_SHARED -#define XLNT_STD_STRING -#endif // XLNT_SHARED -#endif // XLNT_STD_STRING +#endif +#endif // If no API for classes is defined, assume default #ifndef XLNT_CLASS diff --git a/source/cell/cell.cpp b/source/cell/cell.cpp index 4a610c41..72430c0d 100644 --- a/source/cell/cell.cpp +++ b/source/cell/cell.cpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include @@ -34,14 +33,14 @@ enum class condition_type struct section { bool has_value = false; - xlnt::string value; + std::string value; bool has_color = false; - xlnt::string color; + std::string color; bool has_condition = false; condition_type condition = condition_type::invalid; - xlnt::string condition_value; + std::string condition_value; bool has_locale = false; - xlnt::string locale; + std::string locale; section &operator=(const section &other) { @@ -74,13 +73,13 @@ struct format_sections /// /// This should maybe be in a utility header so it can be used elsewhere. /// -std::vector split_string(const xlnt::string &string, char delim) +std::vector split_string(const std::string &string, char delim) { - std::vector split; - xlnt::string::size_type previous_index = 0; + std::vector split; + std::string::size_type previous_index = 0; auto separator_index = string.find(delim); - while (separator_index != xlnt::string::npos) + while (separator_index != std::string::npos) { auto part = string.substr(previous_index, separator_index - previous_index); split.push_back(part); @@ -94,13 +93,13 @@ std::vector split_string(const xlnt::string &string, char delim) return split; } -std::vector split_string_any(const xlnt::string &string, const xlnt::string &delims) +std::vector split_string_any(const std::string &string, const std::string &delims) { - std::vector split; - xlnt::string::size_type previous_index = 0; + std::vector split; + std::string::size_type previous_index = 0; auto separator_index = string.find_first_of(delims); - while (separator_index != xlnt::string::npos) + while (separator_index != std::string::npos) { auto part = string.substr(previous_index, separator_index - previous_index); @@ -118,16 +117,16 @@ std::vector split_string_any(const xlnt::string &string, const xln return split; } -bool is_date_format(const xlnt::string &format_string) +bool is_date_format(const std::string &format_string) { auto not_in = format_string.find_first_not_of("/-:, mMyYdDhHsS"); - return not_in == xlnt::string::npos; + return not_in == std::string::npos; } -bool is_valid_color(const xlnt::string &color) +bool is_valid_color(const std::string &color) { - static const std::vector *colors = - new std::vector( + static const std::vector *colors = + new std::vector( { "Black", "Green" @@ -139,10 +138,10 @@ bool is_valid_color(const xlnt::string &color) "Red" }); - auto compare_color = [&](const xlnt::string &other) { - if (color.length() != other.length()) return false; + auto compare_color = [&](const std::string &other) { + if (color.size() != other.size()) return false; - for (std::size_t i = 0; i < color.length(); i++) + for (std::size_t i = 0; i < color.size(); i++) { if (std::toupper(color[i]) != std::toupper(other[i])) { @@ -156,7 +155,7 @@ bool is_valid_color(const xlnt::string &color) return std::find_if(colors->begin(), colors->end(), compare_color) != colors->end(); } -bool parse_condition(const xlnt::string &string, section &s) +bool parse_condition(const std::string &string, section &s) { s.has_condition = false; s.condition = condition_type::invalid; @@ -209,10 +208,10 @@ bool is_hex(char c) return false; } -const std::unordered_map known_locales() +const std::unordered_map known_locales() { - const std::unordered_map *all = - new std::unordered_map( + const std::unordered_map *all = + new std::unordered_map( { { 0x401, "Arabic - Saudi Arabia" }, { 0x402, "Bulgarian" }, @@ -324,9 +323,9 @@ const std::unordered_map known_locales() return *all; } -bool is_valid_locale(const xlnt::string &locale_string) +bool is_valid_locale(const std::string &locale_string) { - auto country = locale_string.substr(locale_string.find('-') + 1); + std::string country = locale_string.substr(locale_string.find('-') + 1); if (country.empty()) { @@ -341,7 +340,7 @@ bool is_valid_locale(const xlnt::string &locale_string) } } - auto index = country.to_hex(); + auto index = std::stoi(country, 0, 16); auto known_locales_ = known_locales(); @@ -350,14 +349,14 @@ bool is_valid_locale(const xlnt::string &locale_string) return false; } - auto beginning = locale_string.substr(0, locale_string.find('-')); + std::string beginning = locale_string.substr(0, locale_string.find('-')); if (beginning.empty() || beginning[0] != '$') { return false; } - if (beginning.length() == 1) + if (beginning.size() == 1) { return true; } @@ -367,32 +366,32 @@ bool is_valid_locale(const xlnt::string &locale_string) return true; } -section parse_section(const xlnt::string §ion_string) +section parse_section(const std::string §ion_string) { section s; - xlnt::string format_part; - xlnt::string bracket_part; + std::string format_part; + std::string bracket_part; - std::vector bracket_parts; + std::vector bracket_parts; bool in_quotes = false; bool in_brackets = false; - const std::vector bracket_times = { "h", "hh", "m", "mm", "s", "ss" }; + const std::vector bracket_times = { "h", "hh", "m", "mm", "s", "ss" }; - for (std::size_t i = 0; i < section_string.length(); i++) + for (std::size_t i = 0; i < section_string.size(); i++) { if (!in_quotes && section_string[i] == '"') { - format_part.append(section_string[i]); + format_part.push_back(section_string[i]); in_quotes = true; } else if (in_quotes && section_string[i] == '"') { - format_part.append(section_string[i]); + format_part.push_back(section_string[i]); - if (i < section_string.length() - 1 && section_string[i + 1] != '"') + if (i < section_string.size() - 1 && section_string[i + 1] != '"') { in_quotes = false; } @@ -403,8 +402,8 @@ section parse_section(const xlnt::string §ion_string) for (auto bracket_time : bracket_times) { - if (i < section_string.length() - bracket_time.length() && - section_string.substr(i + 1, bracket_time.length()) == bracket_time) + if (i < section_string.size() - bracket_time.size() && + section_string.substr(i + 1, bracket_time.size()) == bracket_time) { in_brackets = false; break; @@ -450,12 +449,12 @@ section parse_section(const xlnt::string §ion_string) } else { - bracket_part.append(section_string[i]); + bracket_part.push_back(section_string[i]); } } else { - format_part.append(section_string[i]); + format_part.push_back(section_string[i]); } } @@ -465,7 +464,7 @@ section parse_section(const xlnt::string §ion_string) return s; } -format_sections parse_format_sections(const xlnt::string &combined) +format_sections parse_format_sections(const std::string &combined) { format_sections result = {}; @@ -522,32 +521,40 @@ format_sections parse_format_sections(const xlnt::string &combined) return result; } -xlnt::string format_section(long double number, const section &format, xlnt::calendar base_date) +std::string format_section(long double number, const section &format, xlnt::calendar base_date) { - const xlnt::string unquoted = "$+(:^'{<=-/)!&~}> "; - xlnt::string format_temp = format.value; - xlnt::string result; + const std::string unquoted = "$+(:^'{<=-/)!&~}> "; + std::string format_temp = format.value; + std::string result; if (is_date_format(format.value)) { - const xlnt::string date_unquoted = ",-/: "; + const std::string date_unquoted = ",-/: "; - const std::vector dates = { "m", "mm", "mmm", "mmmmm", "mmmmmm", "d", "dd", "ddd", "dddd", "yy", + const std::vector dates = { "m", "mm", "mmm", "mmmmm", "mmmmmm", "d", "dd", "ddd", "dddd", "yy", "yyyy", "h", "[h]", "hh", "m", "[m]", "mm", "s", "[s]", "ss", "AM/PM", "am/pm", "A/P", "a/p" }; - const std::vector MonthNames = { "January", "February", "March", + const std::vector MonthNames = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; auto split = split_string_any(format.value, date_unquoted); - xlnt::string::size_type index = 0, prev = 0; + std::string::size_type index = 0, prev = 0; auto d = xlnt::datetime::from_number(number, base_date); bool processed_month = false; + auto lower_string = [](const std::string &s) { + std::string lower; + lower.resize(s.size()); + for (std::size_t i = 0; i < s.size(); i++) + lower[i] = static_cast(std::tolower(s[i])); + return lower; + }; + for (auto part : split) { - while (format.value.substr(index, part.length()) != part) + while (format.value.substr(index, part.size()) != part) { index++; } @@ -555,11 +562,11 @@ xlnt::string format_section(long double number, const section &format, xlnt::cal auto between = format.value.substr(prev, index - prev); result.append(between); - part = part.to_lower(); + part = lower_string(part); if (part == "m" && !processed_month) { - result.append(xlnt::string::from(d.month)); + result.append(std::to_string(d.month)); processed_month = true; } else if (part == "mm" && !processed_month) @@ -569,7 +576,7 @@ xlnt::string format_section(long double number, const section &format, xlnt::cal result.append("0"); } - result.append(xlnt::string::from(d.month)); + result.append(std::to_string(d.month)); processed_month = true; } else if (part == "mmm" && !processed_month) @@ -584,7 +591,7 @@ xlnt::string format_section(long double number, const section &format, xlnt::cal } else if (part == "d") { - result.append(xlnt::string::from(d.day)); + result.append(std::to_string(d.day)); } else if (part == "dd") { @@ -593,16 +600,16 @@ xlnt::string format_section(long double number, const section &format, xlnt::cal result.append("0"); } - result.append(xlnt::string::from(d.day)); + result.append(std::to_string(d.day)); } else if (part == "yyyy") { - result.append(xlnt::string::from(d.year)); + result.append(std::to_string(d.year)); } else if (part == "h") { - result.append(xlnt::string::from(d.hour)); + result.append(std::to_string(d.hour)); processed_month = true; } else if (part == "hh") @@ -612,12 +619,12 @@ xlnt::string format_section(long double number, const section &format, xlnt::cal result.append("0"); } - result.append(xlnt::string::from(d.hour)); + result.append(std::to_string(d.hour)); processed_month = true; } else if (part == "m") { - result.append(xlnt::string::from(d.minute)); + result.append(std::to_string(d.minute)); } else if (part == "mm") { @@ -626,11 +633,11 @@ xlnt::string format_section(long double number, const section &format, xlnt::cal result.append("0"); } - result.append(xlnt::string::from(d.minute)); + result.append(std::to_string(d.minute)); } else if (part == "s") { - result.append(xlnt::string::from(d.second)); + result.append(std::to_string(d.second)); } else if (part == "ss") { @@ -639,7 +646,7 @@ xlnt::string format_section(long double number, const section &format, xlnt::cal result.append("0"); } - result.append(xlnt::string::from(d.second)); + result.append(std::to_string(d.second)); } else if (part == "am/pm" || part == "a/p") { @@ -653,11 +660,11 @@ xlnt::string format_section(long double number, const section &format, xlnt::cal } } - index += part.length(); + index += part.size(); prev = index; } - if (index < format.value.length()) + if (index < format.value.size()) { result.append(format.value.substr(index)); } @@ -666,11 +673,11 @@ xlnt::string format_section(long double number, const section &format, xlnt::cal { if (number == static_cast(number)) { - result = xlnt::string::from(static_cast(number)); + result = std::to_string(static_cast(number)); } else { - result = xlnt::string::from(number); + result = std::to_string(number); } } else if (format.value.substr(0, 8) == "#,##0.00" || format.value.substr(0, 9) == "-#,##0.00") @@ -693,18 +700,18 @@ xlnt::string format_section(long double number, const section &format, xlnt::cal result += "$"; } - result += xlnt::string::from(number < 0 ? -number : number); + result += std::to_string(number < 0 ? -number : number); auto decimal_pos = result.find('.'); - if (decimal_pos != xlnt::string::npos) + if (decimal_pos != std::string::npos) { - result.replace(decimal_pos, U','); + result[decimal_pos] = ','; decimal_pos += 3; - while (decimal_pos < result.length()) + while (decimal_pos < result.size()) { - result.erase(result.length()); + result.pop_back(); } } } @@ -712,13 +719,13 @@ xlnt::string format_section(long double number, const section &format, xlnt::cal return result; } -xlnt::string format_section(const xlnt::string &text, const section &format) +std::string format_section(const std::string &text, const section &format) { auto arobase_index = format.value.find('@'); - xlnt::string first_part, middle_part, last_part; + std::string first_part, middle_part, last_part; - if (arobase_index != xlnt::string::npos) + if (arobase_index != std::string::npos) { first_part = format.value.substr(0, arobase_index); middle_part = text; @@ -729,11 +736,11 @@ xlnt::string format_section(const xlnt::string &text, const section &format) first_part = format.value; } - auto unquote = [](xlnt::string &s) { + auto unquote = [](std::string &s) { if (!s.empty()) { if (s.front() != '"' || s.back() != '"') return false; - s = s.substr(0, s.length() - 2); + s = s.substr(0, s.size() - 2); } return true; @@ -741,13 +748,13 @@ xlnt::string format_section(const xlnt::string &text, const section &format) if (!unquote(first_part) || !unquote(last_part)) { - throw std::runtime_error("additional text must be enclosed in quotes"); + throw std::runtime_error(std::string("additional text must be enclosed in quotes: ") + format.value); } return first_part + middle_part + last_part; } -xlnt::string format_number(long double number, const xlnt::string &format, xlnt::calendar base_date) +std::string format_number(long double number, const std::string &format, xlnt::calendar base_date) { auto sections = parse_format_sections(format); @@ -764,7 +771,7 @@ xlnt::string format_number(long double number, const xlnt::string &format, xlnt: return format_section(number, sections.third, base_date); } -xlnt::string format_text(const xlnt::string &text, const xlnt::string &format) +std::string format_text(const std::string &text, const std::string &format) { if (format == "General") return text; auto sections = parse_format_sections(format); @@ -774,10 +781,10 @@ xlnt::string format_text(const xlnt::string &text, const xlnt::string &format) namespace xlnt { -const std::unordered_map &cell::error_codes() +const std::unordered_map &cell::error_codes() { - static const std::unordered_map *codes = - new std::unordered_map({ { "#NULL!", 0 }, { "#DIV/0!", 1 }, { "#VALUE!", 2 }, + static const std::unordered_map *codes = + new std::unordered_map({ { "#NULL!", 0 }, { "#DIV/0!", 1 }, { "#VALUE!", 2 }, { "#REF!", 3 }, { "#NAME?", 4 }, { "#NUM!", 5 }, { "#N/A!", 6 } }); @@ -810,117 +817,116 @@ bool cell::garbage_collectible() const } template <> -XLNT_FUNCTION void cell::set_value(bool b) +void cell::set_value(bool b) { d_->value_numeric_ = b ? 1 : 0; d_->type_ = type::boolean; } template <> -XLNT_FUNCTION void cell::set_value(std::int8_t i) +void cell::set_value(std::int8_t i) { d_->value_numeric_ = static_cast(i); d_->type_ = type::numeric; } template <> -XLNT_FUNCTION void cell::set_value(std::int16_t i) +void cell::set_value(std::int16_t i) { d_->value_numeric_ = static_cast(i); d_->type_ = type::numeric; } template <> -XLNT_FUNCTION void cell::set_value(std::int32_t i) +void cell::set_value(std::int32_t i) { d_->value_numeric_ = static_cast(i); d_->type_ = type::numeric; } template <> -XLNT_FUNCTION void cell::set_value(std::int64_t i) +void cell::set_value(std::int64_t i) { d_->value_numeric_ = static_cast(i); d_->type_ = type::numeric; } template <> -XLNT_FUNCTION void cell::set_value(std::uint8_t i) +void cell::set_value(std::uint8_t i) { d_->value_numeric_ = static_cast(i); d_->type_ = type::numeric; } template <> -XLNT_FUNCTION void cell::set_value(std::uint16_t i) +void cell::set_value(std::uint16_t i) { d_->value_numeric_ = static_cast(i); d_->type_ = type::numeric; } template <> -XLNT_FUNCTION void cell::set_value(std::uint32_t i) +void cell::set_value(std::uint32_t i) { d_->value_numeric_ = static_cast(i); d_->type_ = type::numeric; } template <> -XLNT_FUNCTION void cell::set_value(std::uint64_t i) +void cell::set_value(std::uint64_t i) { d_->value_numeric_ = static_cast(i); d_->type_ = type::numeric; } -#ifdef _MSC_VER +#ifdef _WIN32 template <> -XLNT_FUNCTION void cell::set_value(unsigned long i) +void cell::set_value(unsigned long i) { d_->value_numeric_ = static_cast(i); d_->type_ = type::numeric; } -#endif // _MSC_VER +#endif -//TODO: base this on 64-bit model (i.e. LLP64/LP64) rather than system/compiler #ifdef __linux template <> -XLNT_FUNCTION void cell::set_value(long long i) +void cell::set_value(long long i) { d_->value_numeric_ = static_cast(i); d_->type_ = type::numeric; } template <> -XLNT_FUNCTION void cell::set_value(unsigned long long i) +void cell::set_value(unsigned long long i) { d_->value_numeric_ = static_cast(i); d_->type_ = type::numeric; } -#endif // __linux +#endif template <> -XLNT_FUNCTION void cell::set_value(float f) +void cell::set_value(float f) { d_->value_numeric_ = static_cast(f); d_->type_ = type::numeric; } template <> -XLNT_FUNCTION void cell::set_value(double d) +void cell::set_value(double d) { d_->value_numeric_ = static_cast(d); d_->type_ = type::numeric; } template <> -XLNT_FUNCTION void cell::set_value(long double d) +void cell::set_value(long double d) { d_->value_numeric_ = static_cast(d); d_->type_ = type::numeric; } template <> -XLNT_FUNCTION void cell::set_value(string s) +void cell::set_value(std::string s) { d_->set_string(s, get_parent().get_parent().get_guess_types()); @@ -931,13 +937,13 @@ XLNT_FUNCTION void cell::set_value(string s) } template <> -XLNT_FUNCTION void cell::set_value(char const *c) +void cell::set_value(char const *c) { - set_value(string(c)); + set_value(std::string(c)); } template <> -XLNT_FUNCTION void cell::set_value(cell c) +void cell::set_value(cell c) { d_->type_ = c.d_->type_; d_->value_numeric_ = c.d_->value_numeric_; @@ -950,7 +956,7 @@ XLNT_FUNCTION void cell::set_value(cell c) } template <> -XLNT_FUNCTION void cell::set_value(date d) +void cell::set_value(date d) { d_->type_ = type::numeric; d_->value_numeric_ = d.to_number(get_base_date()); @@ -958,7 +964,7 @@ XLNT_FUNCTION void cell::set_value(date d) } template <> -XLNT_FUNCTION void cell::set_value(datetime d) +void cell::set_value(datetime d) { d_->type_ = type::numeric; d_->value_numeric_ = d.to_number(get_base_date()); @@ -966,7 +972,7 @@ XLNT_FUNCTION void cell::set_value(datetime d) } template <> -XLNT_FUNCTION void cell::set_value(time t) +void cell::set_value(time t) { d_->type_ = type::numeric; d_->value_numeric_ = t.to_number(); @@ -974,21 +980,13 @@ XLNT_FUNCTION void cell::set_value(time t) } template <> -XLNT_FUNCTION void cell::set_value(timedelta t) +void cell::set_value(timedelta t) { d_->type_ = type::numeric; d_->value_numeric_ = t.to_number(); set_number_format(number_format::date_timedelta()); } -#ifdef XLNT_STD_STRING -template<> -XLNT_FUNCTION void cell::set_value(std::string str) -{ - set_value(string(str.data())); -} -#endif - row_t cell::get_row() const { return d_->row_; @@ -1053,22 +1051,12 @@ cell &cell::operator=(const cell &rhs) return *this; } -XLNT_FUNCTION bool operator==(std::nullptr_t, const cell &cell) -{ - return cell == nullptr; -} - -XLNT_FUNCTION bool operator<(const cell left, const cell right) +bool operator<(cell left, cell right) { return left.get_reference() < right.get_reference(); } -XLNT_FUNCTION std::ostream &operator<<(std::ostream &stream, const xlnt::cell &cell) -{ - return stream << std::string(cell.to_string().data()); -} - -string cell::to_repr() const +std::string cell::to_repr() const { return "parent_).get_title() + "." + get_reference().to_string() + ">"; } @@ -1088,9 +1076,9 @@ bool cell::has_hyperlink() const return d_->has_hyperlink_; } -void cell::set_hyperlink(const string &hyperlink) +void cell::set_hyperlink(const std::string &hyperlink) { - if (hyperlink.length() == 0 || hyperlink.find(':') == xlnt::string::npos) + if (hyperlink.length() == 0 || std::find(hyperlink.begin(), hyperlink.end(), ':') == hyperlink.end()) { throw data_type_exception(); } @@ -1104,7 +1092,7 @@ void cell::set_hyperlink(const string &hyperlink) } } -void cell::set_formula(const string &formula) +void cell::set_formula(const std::string &formula) { if (formula.length() == 0) { @@ -1126,7 +1114,7 @@ bool cell::has_formula() const return !d_->formula_.empty(); } -string cell::get_formula() const +std::string cell::get_formula() const { if (d_->formula_.empty()) { @@ -1171,7 +1159,7 @@ bool cell::has_comment() const return d_->comment_ != nullptr; } -void cell::set_error(const string &error) +void cell::set_error(const std::string &error) { if (error.length() == 0 || error[0] != '#') { @@ -1328,105 +1316,105 @@ void cell::clear_value() } template <> -XLNT_FUNCTION bool cell::get_value() const +bool cell::get_value() const { return d_->value_numeric_ != 0; } template <> -XLNT_FUNCTION std::int8_t cell::get_value() const +std::int8_t cell::get_value() const { return static_cast(d_->value_numeric_); } template <> -XLNT_FUNCTION std::int16_t cell::get_value() const +std::int16_t cell::get_value() const { return static_cast(d_->value_numeric_); } template <> -XLNT_FUNCTION std::int32_t cell::get_value() const +std::int32_t cell::get_value() const { return static_cast(d_->value_numeric_); } template <> -XLNT_FUNCTION std::int64_t cell::get_value() const +std::int64_t cell::get_value() const { return static_cast(d_->value_numeric_); } template <> -XLNT_FUNCTION std::uint8_t cell::get_value() const +std::uint8_t cell::get_value() const { return static_cast(d_->value_numeric_); } template <> -XLNT_FUNCTION std::uint16_t cell::get_value() const +std::uint16_t cell::get_value() const { return static_cast(d_->value_numeric_); } template <> -XLNT_FUNCTION std::uint32_t cell::get_value() const +std::uint32_t cell::get_value() const { return static_cast(d_->value_numeric_); } template <> -XLNT_FUNCTION std::uint64_t cell::get_value() const +std::uint64_t cell::get_value() const { return static_cast(d_->value_numeric_); } #ifdef __linux template <> -XLNT_FUNCTION long long int cell::get_value() const +long long int cell::get_value() const { return static_cast(d_->value_numeric_); } #endif template <> -XLNT_FUNCTION float cell::get_value() const +float cell::get_value() const { return static_cast(d_->value_numeric_); } template <> -XLNT_FUNCTION double cell::get_value() const +double cell::get_value() const { return static_cast(d_->value_numeric_); } template <> -XLNT_FUNCTION long double cell::get_value() const +long double cell::get_value() const { return d_->value_numeric_; } template <> -XLNT_FUNCTION time cell::get_value() const +time cell::get_value() const { return time::from_number(d_->value_numeric_); } template <> -XLNT_FUNCTION datetime cell::get_value() const +datetime cell::get_value() const { return datetime::from_number(d_->value_numeric_, get_base_date()); } template <> -XLNT_FUNCTION date cell::get_value() const +date cell::get_value() const { return date::from_number(static_cast(d_->value_numeric_), get_base_date()); } template <> -XLNT_FUNCTION timedelta cell::get_value() const +timedelta cell::get_value() const { return timedelta::from_number(d_->value_numeric_); } @@ -1438,25 +1426,17 @@ void cell::set_number_format(const number_format &number_format_) } template <> -XLNT_FUNCTION string cell::get_value() const +std::string cell::get_value() const { return d_->value_string_; } -#ifdef XLNT_STD_STRING -template<> -XLNT_FUNCTION std::string cell::get_value() const -{ - return std::string(d_->value_string_.data()); -} -#endif - bool cell::has_value() const { return d_->type_ != cell::type::null; } -string cell::to_string() const +std::string cell::to_string() const { auto nf = get_number_format(); @@ -1469,7 +1449,7 @@ string cell::to_string() const case cell::type::string: case cell::type::formula: case cell::type::error: - return format_text(get_value(), nf.get_format_string()); + return format_text(get_value(), nf.get_format_string()); case cell::type::boolean: return get_value() == 0 ? "FALSE" : "TRUE"; default: diff --git a/source/cell/cell_reference.cpp b/source/cell/cell_reference.cpp index ba798bc1..b59a91ad 100644 --- a/source/cell/cell_reference.cpp +++ b/source/cell/cell_reference.cpp @@ -25,7 +25,7 @@ cell_reference::cell_reference() : cell_reference(1, 1) { } -cell_reference::cell_reference(const string &string) +cell_reference::cell_reference(const std::string &string) { auto split = split_reference(string, absolute_column_, absolute_row_); @@ -34,11 +34,11 @@ cell_reference::cell_reference(const string &string) } cell_reference::cell_reference(const char *reference_string) - : cell_reference(string(reference_string)) + : cell_reference(std::string(reference_string)) { } -cell_reference::cell_reference(const string &column, row_t row) +cell_reference::cell_reference(const std::string &column, row_t row) : cell_reference(column_t(column), row) { } @@ -57,9 +57,9 @@ range_reference cell_reference::operator, (const xlnt::cell_reference &other) co return range_reference(*this, other); } -string cell_reference::to_string() const +std::string cell_reference::to_string() const { - string string_representation; + std::string string_representation; if (absolute_column_) { @@ -73,7 +73,7 @@ string cell_reference::to_string() const string_representation.append("$"); } - string_representation.append(string::from(row_)); + string_representation.append(std::to_string(row_)); return string_representation; } @@ -83,61 +83,79 @@ range_reference cell_reference::to_range() const return range_reference(column_, row_, column_, row_); } -std::pair cell_reference::split_reference(const string &reference_string, +std::pair cell_reference::split_reference(const std::string &reference_string, bool &absolute_column, bool &absolute_row) { absolute_column = false; absolute_row = false; - - auto is_alpha = [](string::code_point c) - { - return (c >= U'A' && c <= U'Z') || (c >= U'a' && c <= U'z'); - }; - - auto upper_ref_string = reference_string.to_upper(); - auto iter = upper_ref_string.begin(); - auto end = upper_ref_string.end(); - - while(iter != end && (is_alpha(*iter) || *iter == U'$')) - { - ++iter; - } - - string column_string(upper_ref_string.begin(), iter); - - if (column_string.length() > 1 && column_string.front() == '$') - { - absolute_column = true; - column_string.erase(0); - } - if (column_string.length() > 1 && column_string.back() == '$') + // Convert a coordinate string like 'B12' to a tuple ('B', 12) + bool column_part = true; + + std::string column_string; + + for (auto character : reference_string) { - absolute_row = true; - column_string.erase(column_string.length() - 1); - } - - string row_string(iter, end); - - auto is_digit = [](string::code_point c) - { - return (c >= U'0' && c <= U'9'); - }; - - for(auto c : row_string) - { - if(!is_digit(c)) + char upper = std::toupper(character, std::locale::classic()); + + if (std::isalpha(character, std::locale::classic())) { - throw cell_coordinates_exception(reference_string); + if (column_part) + { + column_string.append(1, upper); + } + else + { + throw cell_coordinates_exception(reference_string); + } + } + else if (character == '$') + { + if (column_part) + { + if (column_string.empty()) + { + column_string.append(1, upper); + } + else + { + column_part = false; + } + } + } + else + { + if (column_part) + { + column_part = false; + } + else if (!std::isdigit(character, std::locale::classic())) + { + throw cell_coordinates_exception(reference_string); + } } } - - if (column_string.length() == 0 || row_string.length() == 0) + + std::string row_string = reference_string.substr(column_string.length()); + + if (row_string.length() == 0) { throw cell_coordinates_exception(reference_string); } - return { column_string, row_string.to() }; + if (column_string[0] == '$') + { + absolute_row = true; + column_string = column_string.substr(1); + } + + if (row_string[0] == '$') + { + absolute_column = true; + row_string = row_string.substr(1); + } + + return { column_string, std::stoi(row_string) }; } cell_reference cell_reference::make_offset(int column_offset, int row_offset) const diff --git a/source/cell/comment.cpp b/source/cell/comment.cpp index 12430b16..2801e2ff 100644 --- a/source/cell/comment.cpp +++ b/source/cell/comment.cpp @@ -9,7 +9,7 @@ comment::comment(detail::comment_impl *d) : d_(d) { } -comment::comment(cell parent, const string &text, const string &author) : d_(nullptr) +comment::comment(cell parent, const std::string &text, const std::string &author) : d_(nullptr) { d_ = parent.get_comment().d_; d_->text_ = text; @@ -24,12 +24,12 @@ comment::~comment() { } -string comment::get_author() const +std::string comment::get_author() const { return d_->author_; } -string comment::get_text() const +std::string comment::get_text() const { return d_->text_; } diff --git a/source/cell/tests/test_cell.hpp b/source/cell/tests/test_cell.hpp index 85fd13e0..46f46ba0 100644 --- a/source/cell/tests/test_cell.hpp +++ b/source/cell/tests/test_cell.hpp @@ -145,7 +145,7 @@ public: cell.set_value("="); TS_ASSERT(cell.get_data_type() == xlnt::cell::type::string); - TS_ASSERT(cell.get_value() == "="); + TS_ASSERT(cell.get_value() == "="); TS_ASSERT(!cell.has_formula()); } @@ -228,7 +228,7 @@ public: cell.set_value(xlnt::datetime::today()); cell.set_value("testme"); TS_ASSERT(!cell.is_date()); - TS_ASSERT(cell.get_value() == "testme"); + TS_ASSERT(cell.get_value() == "testme"); } void test_cell_formatted_as_date3() @@ -252,15 +252,14 @@ public: for(auto i : illegal_chrs) { - xlnt::string str; - str.append(char(i)); + std::string str(1, i); TS_ASSERT_THROWS(cell.set_value(str), xlnt::illegal_character_error); } - cell.set_value(xlnt::string("\41")); // ! - cell.set_value(xlnt::string("\t")); // Tab - cell.set_value(xlnt::string("\n")); // Newline - cell.set_value(xlnt::string("\r")); // Carriage return + cell.set_value(std::string(1, 33)); + cell.set_value(std::string(1, 9)); // Tab + cell.set_value(std::string(1, 10)); // Newline + cell.set_value(std::string(1, 13)); // Carriage return cell.set_value(" Leading and trailing spaces are legal "); } /* @@ -361,7 +360,7 @@ public: { /* unsigned char pound = 163; - auto test_string = "Compount Value (" + xlnt::string(pound) + ")"; + auto test_string = "Compount Value (" + std::string(pound) + ")"; auto ws = wb.create_sheet(); cell = ws[xlnt::cell_reference("A1")]; TS_ASSERT_THROWS(cell.check_string(test_string), xlnt::unicode_decode_error); diff --git a/source/cell/types.cpp b/source/cell/types.cpp index dd630ed6..4e211839 100644 --- a/source/cell/types.cpp +++ b/source/cell/types.cpp @@ -7,7 +7,7 @@ namespace xlnt { -column_t::index_t column_t::column_index_from_string(const string &column_string) +column_t::index_t column_t::column_index_from_string(const std::string &column_string) { if (column_string.length() > 3 || column_string.empty()) { @@ -16,24 +16,15 @@ column_t::index_t column_t::column_index_from_string(const string &column_string column_t::index_t column_index = 0; int place = 1; - - auto is_alpha = [](string::code_point c) - { - return (c >= U'A' && c <= U'Z') || (c >= U'a' && c <= U'z'); - }; - - auto column_string_upper = column_string.to_upper(); for (int i = static_cast(column_string.length()) - 1; i >= 0; i--) { - auto index = static_cast(i); - - if (!is_alpha(column_string[index])) + if (!std::isalpha(column_string[static_cast(i)], std::locale::classic())) { throw column_string_index_exception(); } - auto char_index = column_string_upper[index] - U'A'; + auto char_index = std::toupper(column_string[static_cast(i)], std::locale::classic()) - 'A'; column_index += static_cast((char_index + 1) * place); place *= 26; @@ -46,18 +37,18 @@ column_t::index_t column_t::column_index_from_string(const string &column_string // Right shift the column col_idx by 26 to find column letters in reverse // order.These numbers are 1 - based, and can be converted to ASCII // ordinals by adding 64. -string column_t::column_string_from_index(column_t::index_t column_index) +std::string column_t::column_string_from_index(column_t::index_t column_index) { // these indicies corrospond to A->ZZZ and include all allowed // columns if (column_index < constants::MinColumn() || column_index > constants::MaxColumn()) { - // auto msg = "Column index out of bounds: " + string::from(column_index); + // auto msg = "Column index out of bounds: " + std::to_string(column_index); throw column_string_index_exception(); } int temp = static_cast(column_index); - string column_letter = ""; + std::string column_letter = ""; while (temp > 0) { @@ -70,9 +61,7 @@ string column_t::column_string_from_index(column_t::index_t column_index) remainder = 26; } - string char_string; - char_string.append(char(remainder + 64)); - column_letter = char_string + column_letter; + column_letter = std::string(1, char(remainder + 64)) + column_letter; temp = quotient; } diff --git a/source/detail/cell_impl.hpp b/source/detail/cell_impl.hpp index b2feed50..846bf3e5 100644 --- a/source/detail/cell_impl.hpp +++ b/source/detail/cell_impl.hpp @@ -5,34 +5,33 @@ #include #include #include +#include +#include #include #include -#include -#include -#include -#include +#include "comment_impl.hpp" namespace { // return s after checking encoding, size, and illegal characters -xlnt::string check_string(xlnt::string s) +std::string check_string(std::string s) { - if (s.length() == 0) + if (s.size() == 0) { return s; } // check encoding? - if (s.length() > 32767) + if (s.size() > 32767) { s = s.substr(0, 32767); // max string length in Excel } - for (auto c : s) + for (char c : s) { - if (c <= 8 || c == 11 || c == 12 || (c >= 14 && c <= 31)) + if (c >= 0 && (c <= 8 || c == 11 || c == 12 || (c >= 14 && c <= 31))) { throw xlnt::illegal_character_error(c); } @@ -41,20 +40,20 @@ xlnt::string check_string(xlnt::string s) return s; } -std::pair cast_numeric(const xlnt::string &s) +std::pair cast_numeric(const std::string &s) { - const char *str = s.data(); + const char *str = s.c_str(); char *str_end = nullptr; auto result = std::strtold(str, &str_end); - if (str_end != str + s.length()) return { false, 0 }; + if (str_end != str + s.size()) return { false, 0 }; return { true, result }; } -std::pair cast_percentage(const xlnt::string &s) +std::pair cast_percentage(const std::string &s) { if (s.back() == '%') { - auto number = cast_numeric(s.substr(0, s.length() - 1)); + auto number = cast_numeric(s.substr(0, s.size() - 1)); if (number.first) { @@ -65,44 +64,38 @@ std::pair cast_percentage(const xlnt::string &s) return { false, 0 }; } -std::pair cast_time(const xlnt::string &s) +std::pair cast_time(const std::string &s) { xlnt::time result; try { auto last_colon = s.find_last_of(':'); - - if (last_colon == xlnt::string::npos) - { - return { false, result }; - } - - double seconds = s.substr(last_colon + 1).to(); + if (last_colon == std::string::npos) return { false, result }; + double seconds = std::stod(s.substr(last_colon + 1)); result.second = static_cast(seconds); result.microsecond = static_cast((seconds - static_cast(result.second)) * 1e6); - auto first_colon = s.find(':'); + auto first_colon = s.find_first_of(':'); if (first_colon == last_colon) { auto decimal_pos = s.find('.'); - - if (decimal_pos != xlnt::string::npos) + if (decimal_pos != std::string::npos) { - result.minute = s.substr(0, first_colon).to(); + result.minute = std::stoi(s.substr(0, first_colon)); } else { - result.hour = s.substr(0, first_colon).to(); + result.hour = std::stoi(s.substr(0, first_colon)); result.minute = result.second; result.second = 0; } } else { - result.hour = s.substr(0, first_colon).to(); - result.minute = s.substr(first_colon + 1, last_colon - first_colon - 1).to(); + result.hour = std::stoi(s.substr(0, first_colon)); + result.minute = std::stoi(s.substr(first_colon + 1, last_colon - first_colon - 1)); } } catch (std::invalid_argument) @@ -136,16 +129,16 @@ struct cell_impl return xlnt::cell(this); } - void set_string(const string &s, bool guess_types) + void set_string(const std::string &s, bool guess_types) { value_string_ = check_string(s); type_ = cell::type::string; - if (value_string_.length() > 1 && value_string_.front() == '=') + if (value_string_.size() > 1 && value_string_.front() == '=') { formula_ = value_string_; type_ = cell::type::formula; - value_string_.length(); + value_string_.clear(); } else if (cell::error_codes().find(s) != cell::error_codes().end()) { @@ -192,10 +185,10 @@ struct cell_impl column_t column_; row_t row_; - string value_string_; + std::string value_string_; long double value_numeric_; - string formula_; + std::string formula_; bool has_hyperlink_; relationship hyperlink_; diff --git a/source/detail/comment_impl.hpp b/source/detail/comment_impl.hpp index 75272f18..1c762502 100644 --- a/source/detail/comment_impl.hpp +++ b/source/detail/comment_impl.hpp @@ -1,7 +1,6 @@ #pragma once #include -#include namespace xlnt { namespace detail { @@ -11,12 +10,12 @@ struct cell_impl; struct comment_impl { comment_impl(); - comment_impl(cell_impl *parent, const string &text, const string &author); + comment_impl(cell_impl *parent, const std::string &text, const std::string &author); comment_impl(const comment_impl &rhs); comment_impl &operator=(const comment_impl &rhs); - string text_; - string author_; + std::string text_; + std::string author_; }; } // namespace detail diff --git a/source/detail/constants.cpp b/source/detail/constants.cpp index 56c2c17c..016ec52f 100644 --- a/source/detail/constants.cpp +++ b/source/detail/constants.cpp @@ -2,7 +2,7 @@ #include -#include +#include "xlnt_config.hpp" namespace xlnt { @@ -42,27 +42,27 @@ const column_t constants::MaxColumn() } // constants -const string constants::PackageProps() { return "docProps"; } -const string constants::PackageXl() { return "xl"; } -const string constants::PackageRels() { return "_rels"; } -const string constants::PackageTheme() { return PackageXl() + "/" + "theme"; } -const string constants::PackageWorksheets() { return PackageXl() + "/" + "worksheets"; } -const string constants::PackageDrawings() { return PackageXl() + "/" + "drawings"; } -const string constants::PackageCharts() { return PackageXl() + "/" + "charts"; } +const std::string constants::PackageProps() { return "docProps"; } +const std::string constants::PackageXl() { return "xl"; } +const std::string constants::PackageRels() { return "_rels"; } +const std::string constants::PackageTheme() { return PackageXl() + "/" + "theme"; } +const std::string constants::PackageWorksheets() { return PackageXl() + "/" + "worksheets"; } +const std::string constants::PackageDrawings() { return PackageXl() + "/" + "drawings"; } +const std::string constants::PackageCharts() { return PackageXl() + "/" + "charts"; } -const string constants::ArcContentTypes() { return "[Content_Types].xml"; } -const string constants::ArcRootRels() { return PackageRels() + "/.rels"; } -const string constants::ArcWorkbookRels() { return PackageXl() + "/" + PackageRels() + "/workbook.xml.rels"; } -const string constants::ArcCore() { return PackageProps() + "/core.xml"; } -const string constants::ArcApp() { return PackageProps() + "/app.xml"; } -const string constants::ArcWorkbook() { return PackageXl() + "/workbook.xml"; } -const string constants::ArcStyles() { return PackageXl() + "/styles.xml"; } -const string constants::ArcTheme() { return PackageTheme() + "/theme1.xml"; } -const string constants::ArcSharedString() { return PackageXl() + "/sharedStrings.xml"; } +const std::string constants::ArcContentTypes() { return "[Content_Types].xml"; } +const std::string constants::ArcRootRels() { return PackageRels() + "/.rels"; } +const std::string constants::ArcWorkbookRels() { return PackageXl() + "/" + PackageRels() + "/workbook.xml.rels"; } +const std::string constants::ArcCore() { return PackageProps() + "/core.xml"; } +const std::string constants::ArcApp() { return PackageProps() + "/app.xml"; } +const std::string constants::ArcWorkbook() { return PackageXl() + "/workbook.xml"; } +const std::string constants::ArcStyles() { return PackageXl() + "/styles.xml"; } +const std::string constants::ArcTheme() { return PackageTheme() + "/theme1.xml"; } +const std::string constants::ArcSharedString() { return PackageXl() + "/sharedStrings.xml"; } -const std::unordered_map constants::Namespaces() +const std::unordered_map constants::Namespaces() { - const std::unordered_map namespaces = + const std::unordered_map namespaces = { { "spreadsheetml", "http://schemas.openxmlformats.org/spreadsheetml/2006/main" }, { "content-types", "http://schemas.openxmlformats.org/package/2006/content-types" }, @@ -81,7 +81,7 @@ const std::unordered_map constants::Namespaces() return namespaces; } -const string constants::Namespace(const string &id) +const std::string constants::Namespace(const std::string &id) { return Namespaces().find(id)->second; } diff --git a/source/detail/constants.hpp b/source/detail/constants.hpp index bd2ea522..9c1676c6 100644 --- a/source/detail/constants.hpp +++ b/source/detail/constants.hpp @@ -15,27 +15,27 @@ struct constants static const column_t MaxColumn(); // constants - static const string PackageProps(); - static const string PackageXl(); - static const string PackageRels(); - static const string PackageTheme(); - static const string PackageWorksheets(); - static const string PackageDrawings(); - static const string PackageCharts(); + static const std::string PackageProps(); + static const std::string PackageXl(); + static const std::string PackageRels(); + static const std::string PackageTheme(); + static const std::string PackageWorksheets(); + static const std::string PackageDrawings(); + static const std::string PackageCharts(); - static const string ArcContentTypes(); - static const string ArcRootRels(); - static const string ArcWorkbookRels(); - static const string ArcCore(); - static const string ArcApp(); - static const string ArcWorkbook(); - static const string ArcStyles(); - static const string ArcTheme(); - static const string ArcSharedString(); + static const std::string ArcContentTypes(); + static const std::string ArcRootRels(); + static const std::string ArcWorkbookRels(); + static const std::string ArcCore(); + static const std::string ArcApp(); + static const std::string ArcWorkbook(); + static const std::string ArcStyles(); + static const std::string ArcTheme(); + static const std::string ArcSharedString(); - static const std::unordered_map Namespaces(); + static const std::unordered_map Namespaces(); - static const string Namespace(const string &id); + static const std::string Namespace(const std::string &id); }; } // namespace xlnt diff --git a/source/detail/workbook_impl.hpp b/source/detail/workbook_impl.hpp index 262e6af7..81e015f7 100644 --- a/source/detail/workbook_impl.hpp +++ b/source/detail/workbook_impl.hpp @@ -63,7 +63,7 @@ struct workbook_impl std::vector relationships_; std::vector root_relationships_; std::vector drawings_; - std::vector shared_strings_; + std::vector shared_strings_; document_properties properties_; diff --git a/source/detail/worksheet_impl.hpp b/source/detail/worksheet_impl.hpp index 8289b357..0e6d84b0 100644 --- a/source/detail/worksheet_impl.hpp +++ b/source/detail/worksheet_impl.hpp @@ -15,7 +15,7 @@ namespace detail { struct worksheet_impl { - worksheet_impl(workbook *parent_workbook, const string &title) + worksheet_impl(workbook *parent_workbook, const std::string &title) : parent_(parent_workbook), title_(title), freeze_panes_("A1"), comment_count_(0) { page_margins_.set_left(0.75); @@ -59,7 +59,7 @@ struct worksheet_impl workbook *parent_; std::unordered_map column_properties_; std::unordered_map row_properties_; - string title_; + std::string title_; cell_reference freeze_panes_; std::unordered_map> cell_map_; std::vector relationships_; @@ -67,7 +67,7 @@ struct worksheet_impl range_reference auto_filter_; margins page_margins_; std::vector merged_cells_; - std::unordered_map named_ranges_; + std::unordered_map named_ranges_; std::size_t comment_count_; header_footer header_footer_; }; diff --git a/source/detail/xml_document_impl.hpp b/source/detail/xml_document_impl.hpp index 0d14c353..b1f84085 100644 --- a/source/detail/xml_document_impl.hpp +++ b/source/detail/xml_document_impl.hpp @@ -9,7 +9,7 @@ namespace detail { struct xml_document_impl { - string encoding; + std::string encoding; pugi::xml_document doc; }; diff --git a/source/packaging/manifest.cpp b/source/packaging/manifest.cpp index 83cd20f8..e8c0f0b0 100644 --- a/source/packaging/manifest.cpp +++ b/source/packaging/manifest.cpp @@ -5,7 +5,7 @@ namespace { -bool match_path(const xlnt::string &path, const xlnt::string &comparand) +bool match_path(const std::string &path, const std::string &comparand) { if (path == comparand) { @@ -32,7 +32,7 @@ default_type::default_type() { } -default_type::default_type(const string &extension, const string &content_type) +default_type::default_type(const std::string &extension, const std::string &content_type) : extension_(extension), content_type_(content_type) { } @@ -53,7 +53,7 @@ override_type::override_type() { } -override_type::override_type(const string &part_name, const string &content_type) +override_type::override_type(const std::string &part_name, const std::string &content_type) : part_name_(part_name), content_type_(content_type) { } @@ -71,52 +71,52 @@ override_type &override_type::operator=(const override_type &other) return *this; } -bool manifest::has_default_type(const string &extension) const +bool manifest::has_default_type(const std::string &extension) const { return std::find_if(default_types_.begin(), default_types_.end(), [&](const default_type &d) { return d.get_extension() == extension; }) != default_types_.end(); } -bool manifest::has_override_type(const string &part_name) const +bool manifest::has_override_type(const std::string &part_name) const { return std::find_if(override_types_.begin(), override_types_.end(), [&](const override_type &d) { return match_path(d.get_part_name(), part_name); }) != override_types_.end(); } -void manifest::add_default_type(const string &extension, const string &content_type) +void manifest::add_default_type(const std::string &extension, const std::string &content_type) { if(has_default_type(extension)) return; default_types_.push_back(default_type(extension, content_type)); } -void manifest::add_override_type(const string &part_name, const string &content_type) +void manifest::add_override_type(const std::string &part_name, const std::string &content_type) { if(has_override_type(part_name)) return; override_types_.push_back(override_type(part_name, content_type)); } -string manifest::get_default_type(const string &extension) const +std::string manifest::get_default_type(const std::string &extension) const { auto match = std::find_if(default_types_.begin(), default_types_.end(), [&](const default_type &d) { return d.get_extension() == extension; }); if (match == default_types_.end()) { - throw std::runtime_error("no default type found for extension"); + throw std::runtime_error("no default type found for extension: " + extension); } return match->get_content_type(); } -string manifest::get_override_type(const string &part_name) const +std::string manifest::get_override_type(const std::string &part_name) const { auto match = std::find_if(override_types_.begin(), override_types_.end(), [&](const override_type &d) { return match_path(d.get_part_name(), part_name); }); if (match == override_types_.end()) { - throw std::runtime_error("no default type found for part name"); + throw std::runtime_error("no default type found for part name: " + part_name); } return match->get_content_type(); diff --git a/source/packaging/relationship.cpp b/source/packaging/relationship.cpp index 204ece19..8a030d6d 100644 --- a/source/packaging/relationship.cpp +++ b/source/packaging/relationship.cpp @@ -2,7 +2,7 @@ namespace xlnt { -XLNT_FUNCTION relationship::relationship(type t, const string &r_id, const string &target_uri) +relationship::relationship(type t, const std::string &r_id, const std::string &target_uri) : type_(t), id_(r_id), source_uri_(""), target_uri_(target_uri), target_mode_(target_mode::internal) { if (t == type::hyperlink) @@ -11,7 +11,7 @@ XLNT_FUNCTION relationship::relationship(type t, const string &r_id, const strin } } -XLNT_FUNCTION relationship::relationship() +relationship::relationship() : type_(type::invalid), id_(""), source_uri_(""), target_uri_(""), target_mode_(target_mode::internal) { } diff --git a/source/packaging/tests/test_core.hpp b/source/packaging/tests/test_core.hpp index 6ab3cbc8..13963824 100644 --- a/source/packaging/tests/test_core.hpp +++ b/source/packaging/tests/test_core.hpp @@ -28,7 +28,7 @@ public: { auto path = PathHelper::GetDataDirectory() + "/genuine/empty.xlsx"; - const std::vector expected_titles = {"Sheet1 - Text", "Sheet2 - Numbers", "Sheet3 - Formulas", "Sheet4 - Dates"}; + const std::vector expected_titles = {"Sheet1 - Text", "Sheet2 - Numbers", "Sheet3 - Formulas", "Sheet4 - Dates"}; std::size_t i = 0; @@ -57,7 +57,7 @@ public: { auto path = PathHelper::GetDataDirectory() + "/genuine/empty_libre.xlsx"; - const std::vector expected_titles = {"Sheet1 - Text", "Sheet2 - Numbers", "Sheet3 - Formulas", "Sheet4 - Dates"}; + const std::vector expected_titles = {"Sheet1 - Text", "Sheet2 - Numbers", "Sheet3 - Formulas", "Sheet4 - Dates"}; std::size_t i = 0; diff --git a/source/packaging/zip_file.cpp b/source/packaging/zip_file.cpp index 320f405a..850558e0 100644 --- a/source/packaging/zip_file.cpp +++ b/source/packaging/zip_file.cpp @@ -11,13 +11,13 @@ namespace { -xlnt::string get_working_directory() +std::string get_working_directory() { #ifdef _WIN32 TCHAR buffer[MAX_PATH]; GetCurrentDirectory(MAX_PATH, buffer); std::basic_string working_directory(buffer); - return xlnt::string(working_directory.begin(), working_directory.end()); + return std::string(working_directory.begin(), working_directory.end()); #else return ""; #endif @@ -31,9 +31,9 @@ char directory_separator = '/'; char alt_directory_separator = '\\'; #endif -xlnt::string join_path(const std::vector &parts) +std::string join_path(const std::vector &parts) { - xlnt::string joined; + std::string joined; std::size_t i = 0; for (auto part : parts) { @@ -41,19 +41,19 @@ xlnt::string join_path(const std::vector &parts) if (i++ != parts.size() - 1) { - joined.append('/'); + joined.append(1, '/'); } } return joined; } -std::vector split_path(const xlnt::string &path, char delim = directory_separator) +std::vector split_path(const std::string &path, char delim = directory_separator) { - std::vector split; - xlnt::string::size_type previous_index = 0; + std::vector split; + std::string::size_type previous_index = 0; auto separator_index = path.find(delim); - while (separator_index != xlnt::string::npos) + while (separator_index != std::string::npos) { auto part = path.substr(previous_index, separator_index - previous_index); if (part != "..") @@ -190,7 +190,7 @@ zip_file::zip_file() : archive_(new mz_zip_archive()) reset(); } -zip_file::zip_file(const string &filename) : zip_file() +zip_file::zip_file(const std::string &filename) : zip_file() { load(filename); } @@ -218,10 +218,10 @@ void zip_file::load(std::istream &stream) start_read(); } -void zip_file::load(const string &filename) +void zip_file::load(const std::string &filename) { filename_ = filename; - std::ifstream stream(filename.data(), std::ios::binary); + std::ifstream stream(filename, std::ios::binary); load(stream); } @@ -233,10 +233,10 @@ void zip_file::load(const std::vector &bytes) start_read(); } -void zip_file::save(const string &filename) +void zip_file::save(const std::string &filename) { filename_ = filename; - std::ofstream stream(filename.data(), std::ios::binary); + std::ofstream stream(filename, std::ios::binary); save(stream); } @@ -289,7 +289,7 @@ void zip_file::append_comment() auto comment_length = std::min(static_cast(comment.length()), std::numeric_limits::max()); buffer_[buffer_.size() - 2] = static_cast(comment_length); buffer_[buffer_.size() - 1] = static_cast(comment_length >> 8); - std::copy(comment.data(), comment.data() + comment.num_bytes(), std::back_inserter(buffer_)); + std::copy(comment.begin(), comment.end(), std::back_inserter(buffer_)); } } @@ -320,7 +320,7 @@ void zip_file::remove_comment() if (length != 0) { - comment = string(buffer_.data() + position, buffer_.data() + position + length); + comment = std::string(buffer_.data() + position, buffer_.data() + position + length); buffer_.resize(buffer_.size() - length); buffer_[buffer_.size() - 1] = 0; buffer_[buffer_.size() - 2] = 0; @@ -358,14 +358,14 @@ void zip_file::reset() mz_zip_writer_end(archive_.get()); } -zip_info zip_file::getinfo(const string &name) +zip_info zip_file::getinfo(const std::string &name) { if (archive_->m_zip_mode != MZ_ZIP_MODE_READING) { start_read(); } - int index = mz_zip_reader_locate_file(archive_.get(), name.data(), nullptr, 0); + int index = mz_zip_reader_locate_file(archive_.get(), name.c_str(), nullptr, 0); if (index == -1) { @@ -387,8 +387,8 @@ zip_info zip_file::getinfo(int index) zip_info result; - result.filename = string(stat.m_filename, stat.m_filename + std::strlen(stat.m_filename)); - result.comment = string(stat.m_comment, stat.m_comment + stat.m_comment_size); + result.filename = std::string(stat.m_filename, stat.m_filename + std::strlen(stat.m_filename)); + result.comment = std::string(stat.m_comment, stat.m_comment + stat.m_comment_size); result.compress_size = static_cast(stat.m_comp_size); result.file_size = static_cast(stat.m_uncomp_size); result.header_offset = static_cast(stat.m_local_header_ofs); @@ -487,7 +487,7 @@ void zip_file::start_write() } } -void zip_file::write(const string &filename) +void zip_file::write(const std::string &filename) { auto split = split_path(filename); if (split.size() > 1) @@ -498,30 +498,30 @@ void zip_file::write(const string &filename) write(filename, arcname); } -void zip_file::write(const string &filename, const string &arcname) +void zip_file::write(const std::string &filename, const std::string &arcname) { - std::fstream file(filename.data(), std::ios::binary | std::ios::in); + std::fstream file(filename, std::ios::binary | std::ios::in); std::stringstream ss; ss << file.rdbuf(); - string bytes = ss.str().data(); + std::string bytes = ss.str(); writestr(arcname, bytes); } -void zip_file::writestr(const string &arcname, const string &bytes) +void zip_file::writestr(const std::string &arcname, const std::string &bytes) { if (archive_->m_zip_mode != MZ_ZIP_MODE_WRITING) { start_write(); } - if (!mz_zip_writer_add_mem(archive_.get(), arcname.data(), bytes.data(), bytes.length(), MZ_BEST_COMPRESSION)) + if (!mz_zip_writer_add_mem(archive_.get(), arcname.c_str(), bytes.data(), bytes.size(), MZ_BEST_COMPRESSION)) { throw std::runtime_error("write error"); } } -void zip_file::writestr(const zip_info &info, const string &bytes) +void zip_file::writestr(const zip_info &info, const std::string &bytes) { if (info.filename.empty() || info.date_time.year < 1980) { @@ -533,43 +533,43 @@ void zip_file::writestr(const zip_info &info, const string &bytes) start_write(); } - auto crc = crc32buf(bytes.data(), bytes.length()); + auto crc = crc32buf(bytes.c_str(), bytes.size()); - if (!mz_zip_writer_add_mem_ex(archive_.get(), info.filename.data(), bytes.data(), bytes.length(), - info.comment.data(), static_cast(info.comment.length()), + if (!mz_zip_writer_add_mem_ex(archive_.get(), info.filename.c_str(), bytes.data(), bytes.size(), + info.comment.c_str(), static_cast(info.comment.size()), MZ_BEST_COMPRESSION, 0, crc)) { throw std::runtime_error("write error"); } } -string zip_file::read(const zip_info &info) +std::string zip_file::read(const zip_info &info) { std::size_t size; char *data = - static_cast(mz_zip_reader_extract_file_to_heap(archive_.get(), info.filename.data(), &size, 0)); + static_cast(mz_zip_reader_extract_file_to_heap(archive_.get(), info.filename.c_str(), &size, 0)); if (data == nullptr) { throw std::runtime_error("file couldn't be read"); } - string extracted(data, data + size); + std::string extracted(data, data + size); mz_free(data); return extracted; } -string zip_file::read(const string &name) +std::string zip_file::read(const std::string &name) { return read(getinfo(name)); } -bool zip_file::has_file(const string &name) +bool zip_file::has_file(const std::string &name) { if (archive_->m_zip_mode != MZ_ZIP_MODE_READING) { start_read(); } - int index = mz_zip_reader_locate_file(archive_.get(), name.data(), nullptr, 0); + int index = mz_zip_reader_locate_file(archive_.get(), name.c_str(), nullptr, 0); return index != -1; } @@ -596,9 +596,9 @@ std::vector zip_file::infolist() return info; } -std::vector zip_file::namelist() +std::vector zip_file::namelist() { - std::vector names; + std::vector names; for (auto &info : infolist()) { @@ -608,7 +608,7 @@ std::vector zip_file::namelist() return names; } -std::ostream &zip_file::open(const string &name) +std::ostream &zip_file::open(const std::string &name) { return open(getinfo(name)); } @@ -616,19 +616,19 @@ std::ostream &zip_file::open(const string &name) std::ostream &zip_file::open(const zip_info &name) { auto data = read(name); - string data_string(data.begin(), data.end()); + std::string data_string(data.begin(), data.end()); open_stream_ << data_string; return open_stream_; } -void zip_file::extract(const string &member) +void zip_file::extract(const std::string &member) { extract(member, get_working_directory()); } -void zip_file::extract(const string &member, const string &path) +void zip_file::extract(const std::string &member, const std::string &path) { - std::fstream stream(join_path({ path, member }).data(), std::ios::binary | std::ios::out); + std::fstream stream(join_path({ path, member }), std::ios::binary | std::ios::out); stream << open(member).rdbuf(); } @@ -637,18 +637,18 @@ void zip_file::extract(const zip_info &member) extract(member, get_working_directory()); } -void zip_file::extract(const zip_info &member, const string &path) +void zip_file::extract(const zip_info &member, const std::string &path) { - std::fstream stream(join_path({ path, member.filename }).data(), std::ios::binary | std::ios::out); + std::fstream stream(join_path({ path, member.filename }), std::ios::binary | std::ios::out); stream << open(member).rdbuf(); } -void zip_file::extractall(const string &path) +void zip_file::extractall(const std::string &path) { extractall(path, infolist()); } -void zip_file::extractall(const string &path, const std::vector &members) +void zip_file::extractall(const std::string &path, const std::vector &members) { for (auto &member : members) { @@ -656,7 +656,7 @@ void zip_file::extractall(const string &path, const std::vector &members } } -void zip_file::extractall(const string &path, const std::vector &members) +void zip_file::extractall(const std::string &path, const std::vector &members) { for (auto &member : members) { @@ -690,7 +690,7 @@ void zip_file::printdir(std::ostream &stream) sum_length += member.file_size; file_count++; - string length_string = string::from(member.file_size); + std::string length_string = std::to_string(member.file_size); while (length_string.length() < 9) { length_string = " " + length_string; @@ -714,7 +714,7 @@ void zip_file::printdir(std::ostream &stream) stream << "--------- -------" << std::endl; - string length_string = string::from(sum_length); + std::string length_string = std::to_string(sum_length); while (length_string.length() < 9) { length_string = " " + length_string; @@ -723,7 +723,7 @@ void zip_file::printdir(std::ostream &stream) stream << std::endl; } -std::pair zip_file::testzip() +std::pair zip_file::testzip() { if (archive_->m_zip_mode == MZ_ZIP_MODE_INVALID) { @@ -733,7 +733,7 @@ std::pair zip_file::testzip() for (auto &file : infolist()) { auto content = read(file); - auto crc = crc32buf(content.data(), content.length()); + auto crc = crc32buf(content.c_str(), content.size()); if (crc != file.crc) { diff --git a/source/serialization/excel_serializer.cpp b/source/serialization/excel_serializer.cpp index d9c8af6f..f9efe52b 100644 --- a/source/serialization/excel_serializer.cpp +++ b/source/serialization/excel_serializer.cpp @@ -15,7 +15,6 @@ #include #include #include -#include #include #include @@ -23,13 +22,13 @@ namespace { -xlnt::string::size_type find_string_in_string(const xlnt::string &string, const xlnt::string &substring) +std::string::size_type find_string_in_string(const std::string &string, const std::string &substring) { - xlnt::string::size_type possible_match_index = string.find(substring.at(0)); + std::string::size_type possible_match_index = string.find(substring.at(0)); - while (possible_match_index != xlnt::string::npos) + while (possible_match_index != std::string::npos) { - if (string.substr(possible_match_index, substring.length()) == substring) + if (string.substr(possible_match_index, substring.size()) == substring) { return possible_match_index; } @@ -91,7 +90,7 @@ bool load_workbook(xlnt::zip_file &archive, bool guess_types, bool data_only, xl if(archive.has_file(xlnt::constants::ArcSharedString())) { - std::vector shared_strings; + std::vector shared_strings; xlnt::xml_document shared_strings_xml; shared_strings_xml.from_string(archive.read(xlnt::constants::ArcSharedString())); xlnt::shared_strings_serializer::read_shared_strings(shared_strings_xml, shared_strings); @@ -137,16 +136,16 @@ bool load_workbook(xlnt::zip_file &archive, bool guess_types, bool data_only, xl namespace xlnt { -const string excel_serializer::central_directory_signature() +const std::string excel_serializer::central_directory_signature() { return "\x50\x4b\x05\x06"; } -string excel_serializer::repair_central_directory(const string &original) +std::string excel_serializer::repair_central_directory(const std::string &original) { auto pos = find_string_in_string(original, central_directory_signature()); - if (pos != string::npos) + if (pos != std::string::npos) { return original.substr(0, pos + 22); } @@ -167,7 +166,7 @@ bool excel_serializer::load_stream_workbook(std::istream &stream, bool guess_typ return load_virtual_workbook(bytes, guess_types, data_only); } -bool excel_serializer::load_workbook(const string &filename, bool guess_types, bool data_only) +bool excel_serializer::load_workbook(const std::string &filename, bool guess_types, bool data_only) { try { @@ -233,7 +232,7 @@ void excel_serializer::write_worksheets() workbook::index_from_ws_filename(relationship.get_target_uri()) == index) { worksheet_serializer serializer_(ws); - string ws_filename = (relationship.get_target_uri().substr(0, 3) != "xl/" ? "xl/" : "") + relationship.get_target_uri(); + std::string ws_filename = (relationship.get_target_uri().substr(0, 3) != "xl/" ? "xl/" : "") + relationship.get_target_uri(); archive_.writestr(ws_filename, serializer_.write_worksheet().to_string()); break; } @@ -255,7 +254,7 @@ bool excel_serializer::save_stream_workbook(std::ostream &stream, bool as_templa return true; } -bool excel_serializer::save_workbook(const string &filename, bool as_template) +bool excel_serializer::save_workbook(const std::string &filename, bool as_template) { write_data(as_template); archive_.save(filename); diff --git a/source/serialization/manifest_serializer.cpp b/source/serialization/manifest_serializer.cpp index 00f3d47b..e2cd53bf 100644 --- a/source/serialization/manifest_serializer.cpp +++ b/source/serialization/manifest_serializer.cpp @@ -52,14 +52,14 @@ xml_document manifest_serializer::write_manifest() const return xml; } -string manifest_serializer::determine_document_type() const +std::string manifest_serializer::determine_document_type() const { if (!manifest_.has_override_type(constants::ArcWorkbook())) { return "unsupported"; } - string type = manifest_.get_override_type(constants::ArcWorkbook()); + std::string type = manifest_.get_override_type(constants::ArcWorkbook()); if (type == "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml") { diff --git a/source/serialization/relationship_serializer.cpp b/source/serialization/relationship_serializer.cpp index 59051fa5..b548d9f6 100644 --- a/source/serialization/relationship_serializer.cpp +++ b/source/serialization/relationship_serializer.cpp @@ -1,15 +1,15 @@ #include + #include #include #include #include -#include -#include +#include "detail/constants.hpp" namespace { -xlnt::string make_rels_name(const xlnt::string &target) +std::string make_rels_name(const std::string &target) { const char sep = '/'; @@ -32,7 +32,7 @@ relationship_serializer::relationship_serializer(zip_file &archive) : archive_(a { } -std::vector relationship_serializer::read_relationships(const string &target) +std::vector relationship_serializer::read_relationships(const std::string &target) { xml_document xml; xml.from_string(archive_.read(make_rels_name(target))); @@ -48,9 +48,9 @@ std::vector relationship_serializer::read_relationships(const stri continue; } - string id = relationship_node.get_attribute("Id"); - string type = relationship_node.get_attribute("Type"); - string rel_target = relationship_node.get_attribute("Target"); + std::string id = relationship_node.get_attribute("Id"); + std::string type = relationship_node.get_attribute("Type"); + std::string rel_target = relationship_node.get_attribute("Target"); relationships.push_back(xlnt::relationship(type, id, rel_target)); } @@ -59,7 +59,7 @@ std::vector relationship_serializer::read_relationships(const stri } bool relationship_serializer::write_relationships(const std::vector &relationships, - const string &target) + const std::string &target) { xml_document xml; diff --git a/source/serialization/shared_strings_serializer.cpp b/source/serialization/shared_strings_serializer.cpp index d8a7122e..8a3c10bd 100644 --- a/source/serialization/shared_strings_serializer.cpp +++ b/source/serialization/shared_strings_serializer.cpp @@ -4,7 +4,7 @@ namespace xlnt { -xml_document shared_strings_serializer::write_shared_strings(const std::vector &strings) +xml_document shared_strings_serializer::write_shared_strings(const std::vector &strings) { xml_document xml; @@ -12,7 +12,7 @@ xml_document shared_strings_serializer::write_shared_strings(const std::vector &strings) +bool shared_strings_serializer::read_shared_strings(const xml_document &xml, std::vector &strings) { strings.clear(); auto root_node = xml.get_child("sst"); - auto unique_count = root_node.get_attribute("uniqueCount").to(); + auto unique_count = std::stoull(root_node.get_attribute("uniqueCount")); for (const auto &si_node : root_node.get_children()) { diff --git a/source/serialization/style_serializer.cpp b/source/serialization/style_serializer.cpp index 8081dd83..e8ccabb5 100644 --- a/source/serialization/style_serializer.cpp +++ b/source/serialization/style_serializer.cpp @@ -8,16 +8,15 @@ #include #include #include -#include namespace { -bool is_true(const xlnt::string &bool_string) +bool is_true(const std::string &bool_string) { return bool_string == "1"; } -xlnt::protection::type protection_type_from_string(const xlnt::string &type_string) +xlnt::protection::type protection_type_from_string(const std::string &type_string) { if (type_string == "true") { @@ -31,7 +30,7 @@ xlnt::protection::type protection_type_from_string(const xlnt::string &type_stri return xlnt::protection::type::unprotected; }; -xlnt::font::underline_style underline_style_from_string(const xlnt::string &underline_string) +xlnt::font::underline_style underline_style_from_string(const std::string &underline_string) { if (underline_string == "none") { @@ -57,7 +56,7 @@ xlnt::font::underline_style underline_style_from_string(const xlnt::string &unde return xlnt::font::underline_style::none; } -xlnt::fill::pattern_type pattern_fill_type_from_string(const xlnt::string &fill_type) +xlnt::fill::pattern_type pattern_fill_type_from_string(const std::string &fill_type) { if (fill_type == "none") return xlnt::fill::pattern_type::none; if (fill_type == "solid") return xlnt::fill::pattern_type::solid; @@ -65,7 +64,7 @@ xlnt::fill::pattern_type pattern_fill_type_from_string(const xlnt::string &fill_ return xlnt::fill::pattern_type::none; }; -xlnt::border_style border_style_from_string(const xlnt::string &border_style_string) +xlnt::border_style border_style_from_string(const std::string &border_style_string) { if (border_style_string == "none") { @@ -157,7 +156,7 @@ alignment style_serializer::read_alignment(const xml_node &alignment_node) if (has_vertical) { - string vertical = alignment_node.get_attribute("vertical"); + std::string vertical = alignment_node.get_attribute("vertical"); if (vertical == "bottom") { @@ -185,7 +184,7 @@ alignment style_serializer::read_alignment(const xml_node &alignment_node) if (has_horizontal) { - string horizontal = alignment_node.get_attribute("horizontal"); + std::string horizontal = alignment_node.get_attribute("horizontal"); if (horizontal == "left") { @@ -225,7 +224,7 @@ style style_serializer::read_style(const xml_node &style_node) style s; s.apply_number_format(is_true(style_node.get_attribute("applyNumberFormat"))); - s.number_format_id_ = style_node.get_attribute("numFmtId").to(); + s.number_format_id_ = std::stoull(style_node.get_attribute("numFmtId")); bool builtin_format = true; @@ -245,15 +244,15 @@ style style_serializer::read_style(const xml_node &style_node) } s.apply_font(is_true(style_node.get_attribute("applyFont"))); - s.font_id_ = style_node.has_attribute("fontId") ? style_node.get_attribute("fontId").to() : 0; + s.font_id_ = style_node.has_attribute("fontId") ? std::stoull(style_node.get_attribute("fontId")) : 0; s.font_ = workbook_.get_font(s.font_id_); s.apply_fill(is_true(style_node.get_attribute("applyFill"))); - s.fill_id_ = style_node.has_attribute("fillId") ? style_node.get_attribute("fillId").to() : 0; + s.fill_id_ = style_node.has_attribute("fillId") ? std::stoull(style_node.get_attribute("fillId")) : 0; s.fill_ = workbook_.get_fill(s.fill_id_); s.apply_border(is_true(style_node.get_attribute("applyBorder"))); - s.border_id_ = style_node.has_attribute("borderId") ? style_node.get_attribute("borderId").to() : 0; + s.border_id_ = style_node.has_attribute("borderId") ? std::stoull(style_node.get_attribute("borderId")) : 0; s.border_ = workbook_.get_border(s.border_id_); s.apply_protection(style_node.has_attribute("protection")); @@ -319,7 +318,7 @@ bool style_serializer::read_number_formats(const xml_node &number_formats_node) number_format nf; nf.set_format_string(format_string); - nf.set_id(num_fmt_node.get_attribute("numFmtId").to()); + nf.set_id(std::stoull(num_fmt_node.get_attribute("numFmtId"))); workbook_.add_number_format(nf); } @@ -341,7 +340,7 @@ font style_serializer::read_font(const xlnt::xml_node &font_node) { font new_font; - new_font.set_size(font_node.get_child("sz").get_attribute("val").to()); + new_font.set_size(std::stoull(font_node.get_child("sz").get_attribute("val"))); new_font.set_name(font_node.get_child("name").get_attribute("val")); if (font_node.has_child("color")) @@ -351,7 +350,7 @@ font style_serializer::read_font(const xlnt::xml_node &font_node) if (font_node.has_child("family")) { - new_font.set_family(font_node.get_child("family").get_attribute("val").to()); + new_font.set_family(std::stoull(font_node.get_child("family").get_attribute("val"))); } if (font_node.has_child("scheme")) @@ -376,7 +375,7 @@ font style_serializer::read_font(const xlnt::xml_node &font_node) if (font_node.has_child("u")) { - string underline_string = font_node.get_child("u").get_attribute("val"); + std::string underline_string = font_node.get_child("u").get_attribute("val"); new_font.set_underline(underline_style_from_string(underline_string)); } @@ -541,15 +540,15 @@ color style_serializer::read_color(const xml_node &color_node) } else if (color_node.has_attribute("theme")) { - return color(color::type::theme, color_node.get_attribute("theme").to()); + return color(color::type::theme, std::stoull(color_node.get_attribute("theme"))); } else if (color_node.has_attribute("indexed")) { - return color(color::type::indexed, color_node.get_attribute("indexed").to()); + return color(color::type::indexed, std::stoull(color_node.get_attribute("indexed"))); } else if (color_node.has_attribute("auto")) { - return color(color::type::auto_, color_node.get_attribute("auto").to()); + return color(color::type::auto_, std::stoull(color_node.get_attribute("auto"))); } throw std::runtime_error("bad color"); @@ -567,12 +566,12 @@ xml_document style_serializer::write_stylesheet() const auto num_fmts_node = style_sheet_node.add_child("numFmts"); auto num_fmts = workbook_.get_number_formats(); - num_fmts_node.add_attribute("count", string::from(num_fmts.size())); + num_fmts_node.add_attribute("count", std::to_string(num_fmts.size())); for (const auto &num_fmt : num_fmts) { auto num_fmt_node = num_fmts_node.add_child("numFmt"); - num_fmt_node.add_attribute("numFmtId", string::from(num_fmt.get_id())); + num_fmt_node.add_attribute("numFmtId", std::to_string(num_fmt.get_id())); num_fmt_node.add_attribute("formatCode", num_fmt.get_format_string()); } @@ -584,7 +583,7 @@ xml_document style_serializer::write_stylesheet() const fonts.push_back(font()); } - fonts_node.add_attribute("count", string::from(fonts.size())); + fonts_node.add_attribute("count", std::to_string(fonts.size())); // TODO: what does this do? // fonts_node.add_attribute("x14ac:knownFonts", "1"); @@ -625,17 +624,17 @@ xml_document style_serializer::write_stylesheet() const } auto size_node = font_node.add_child("sz"); - size_node.add_attribute("val", string::from(f.get_size())); + size_node.add_attribute("val", std::to_string(f.get_size())); auto color_node = font_node.add_child("color"); if (f.get_color().get_type() == color::type::indexed) { - color_node.add_attribute("indexed", string::from(f.get_color().get_index())); + color_node.add_attribute("indexed", std::to_string(f.get_color().get_index())); } else if (f.get_color().get_type() == color::type::theme) { - color_node.add_attribute("theme", string::from(f.get_color().get_theme())); + color_node.add_attribute("theme", std::to_string(f.get_color().get_theme())); } auto name_node = font_node.add_child("name"); @@ -644,7 +643,7 @@ xml_document style_serializer::write_stylesheet() const if (f.has_family()) { auto family_node = font_node.add_child("family"); - family_node.add_attribute("val", string::from(f.get_family())); + family_node.add_attribute("val", std::to_string(f.get_family())); } if (f.has_scheme()) @@ -656,7 +655,7 @@ xml_document style_serializer::write_stylesheet() const auto fills_node = style_sheet_node.add_child("fills"); const auto &fills = workbook_.get_fills(); - fills_node.add_attribute("count", string::from(fills.size())); + fills_node.add_attribute("count", std::to_string(fills.size())); for (auto &fill_ : fills) { @@ -675,13 +674,13 @@ xml_document style_serializer::write_stylesheet() const switch (fill_.get_foreground_color().get_type()) { case color::type::auto_: - fg_color_node.add_attribute("auto", string::from(fill_.get_foreground_color().get_auto())); + fg_color_node.add_attribute("auto", std::to_string(fill_.get_foreground_color().get_auto())); break; case color::type::theme: - fg_color_node.add_attribute("theme", string::from(fill_.get_foreground_color().get_theme())); + fg_color_node.add_attribute("theme", std::to_string(fill_.get_foreground_color().get_theme())); break; case color::type::indexed: - fg_color_node.add_attribute("indexed", string::from(fill_.get_foreground_color().get_index())); + fg_color_node.add_attribute("indexed", std::to_string(fill_.get_foreground_color().get_index())); break; default: throw std::runtime_error("bad type"); @@ -695,13 +694,13 @@ xml_document style_serializer::write_stylesheet() const switch (fill_.get_background_color().get_type()) { case color::type::auto_: - bg_color_node.add_attribute("auto", string::from(fill_.get_background_color().get_auto())); + bg_color_node.add_attribute("auto", std::to_string(fill_.get_background_color().get_auto())); break; case color::type::theme: - bg_color_node.add_attribute("theme", string::from(fill_.get_background_color().get_theme())); + bg_color_node.add_attribute("theme", std::to_string(fill_.get_background_color().get_theme())); break; case color::type::indexed: - bg_color_node.add_attribute("indexed", string::from(fill_.get_background_color().get_index())); + bg_color_node.add_attribute("indexed", std::to_string(fill_.get_background_color().get_index())); break; default: throw std::runtime_error("bad type"); @@ -719,14 +718,14 @@ xml_document style_serializer::write_stylesheet() const if (fill_.get_gradient_type_string() == "linear") { - gradient_fill_node.add_attribute("degree", string::from(fill_.get_rotation())); + gradient_fill_node.add_attribute("degree", std::to_string(fill_.get_rotation())); } else if (fill_.get_gradient_type_string() == "path") { - gradient_fill_node.add_attribute("left", string::from(fill_.get_gradient_left())); - gradient_fill_node.add_attribute("right", string::from(fill_.get_gradient_right())); - gradient_fill_node.add_attribute("top", string::from(fill_.get_gradient_top())); - gradient_fill_node.add_attribute("bottom", string::from(fill_.get_gradient_bottom())); + gradient_fill_node.add_attribute("left", std::to_string(fill_.get_gradient_left())); + gradient_fill_node.add_attribute("right", std::to_string(fill_.get_gradient_right())); + gradient_fill_node.add_attribute("top", std::to_string(fill_.get_gradient_top())); + gradient_fill_node.add_attribute("bottom", std::to_string(fill_.get_gradient_bottom())); auto start_node = gradient_fill_node.add_child("stop"); start_node.add_attribute("position", "0"); @@ -739,13 +738,13 @@ xml_document style_serializer::write_stylesheet() const auto borders_node = style_sheet_node.add_child("borders"); const auto &borders = workbook_.get_borders(); - borders_node.add_attribute("count", string::from(borders.size())); + borders_node.add_attribute("count", std::to_string(borders.size())); for (const auto &border_ : borders) { auto border_node = borders_node.add_child("border"); - std::vector> sides; + std::vector> sides; sides.push_back(std::make_tuple("start", border_.start, border_.start_assigned)); sides.push_back(std::make_tuple("end", border_.end, border_.end_assigned)); sides.push_back(std::make_tuple("left", border_.left, border_.left_assigned)); @@ -758,7 +757,7 @@ xml_document style_serializer::write_stylesheet() const for (const auto &side_tuple : sides) { - string name = std::get<0>(side_tuple); + std::string name = std::get<0>(side_tuple); const side side_ = std::get<1>(side_tuple); bool assigned = std::get<2>(side_tuple); @@ -768,7 +767,7 @@ xml_document style_serializer::write_stylesheet() const if (side_.is_style_assigned()) { - string style_string; + std::string style_string; switch (side_.get_style()) { @@ -827,11 +826,11 @@ xml_document style_serializer::write_stylesheet() const if (side_.get_color().get_type() == color::type::indexed) { - color_node.add_attribute("indexed", string::from(side_.get_color().get_index())); + color_node.add_attribute("indexed", std::to_string(side_.get_color().get_index())); } else if (side_.get_color().get_type() == color::type::theme) { - color_node.add_attribute("theme", string::from(side_.get_color().get_theme())); + color_node.add_attribute("theme", std::to_string(side_.get_color().get_theme())); } else { @@ -853,22 +852,22 @@ xml_document style_serializer::write_stylesheet() const auto cell_xfs_node = style_sheet_node.add_child("cellXfs"); const auto &styles = workbook_.get_styles(); - cell_xfs_node.add_attribute("count", string::from(styles.size())); + cell_xfs_node.add_attribute("count", std::to_string(styles.size())); for (auto &style : styles) { auto xf_node = cell_xfs_node.add_child("xf"); - xf_node.add_attribute("numFmtId", string::from(style.get_number_format().get_id())); - xf_node.add_attribute("fontId", string::from(style.get_font_id())); + xf_node.add_attribute("numFmtId", std::to_string(style.get_number_format().get_id())); + xf_node.add_attribute("fontId", std::to_string(style.get_font_id())); if (style.fill_apply_) { - xf_node.add_attribute("fillId", string::from(style.get_fill_id())); + xf_node.add_attribute("fillId", std::to_string(style.get_fill_id())); } if (style.border_apply_) { - xf_node.add_attribute("borderId", string::from(style.get_border_id())); + xf_node.add_attribute("borderId", std::to_string(style.get_border_id())); } xf_node.add_attribute("applyNumberFormat", style.number_format_apply_ ? "1" : "0"); @@ -970,12 +969,12 @@ xml_document style_serializer::write_stylesheet() const bool style_serializer::write_number_formats(xml_node number_formats_node) const { - number_formats_node.add_attribute("count", string::from(workbook_.get_number_formats().size())); + number_formats_node.add_attribute("count", std::to_string(workbook_.get_number_formats().size())); for (const auto &num_fmt : workbook_.get_number_formats()) { auto num_fmt_node = number_formats_node.add_child("numFmt"); - num_fmt_node.add_attribute("numFmtId", string::from(num_fmt.get_id())); + num_fmt_node.add_attribute("numFmtId", std::to_string(num_fmt.get_id())); num_fmt_node.add_attribute("formatCode", num_fmt.get_format_string()); } diff --git a/source/serialization/tests/test_read.hpp b/source/serialization/tests/test_read.hpp index e8aad916..92238ec6 100644 --- a/source/serialization/tests/test_read.hpp +++ b/source/serialization/tests/test_read.hpp @@ -35,7 +35,7 @@ public: void test_read_standard_workbook_from_fileobj() { auto path = PathHelper::GetDataDirectory("/genuine/empty.xlsx"); - std::ifstream fo(path.data(), std::ios::binary); + std::ifstream fo(path, std::ios::binary); xlnt::workbook wb; xlnt::excel_serializer serializer(wb); @@ -51,7 +51,7 @@ public: auto sheet2 = wb.get_sheet_by_name("Sheet2 - Numbers"); TS_ASSERT_DIFFERS(sheet2, nullptr); - TS_ASSERT_EQUALS("This is cell G5", sheet2.get_cell("G5").get_value()); + TS_ASSERT_EQUALS("This is cell G5", sheet2.get_cell("G5").get_value()); TS_ASSERT_EQUALS(18, sheet2.get_cell("D18").get_value()); TS_ASSERT_EQUALS(true, sheet2.get_cell("G9").get_value()); TS_ASSERT_EQUALS(false, sheet2.get_cell("G10").get_value()); @@ -216,8 +216,8 @@ public: void test_repair_central_directory() { - xlnt::string data_a = "foobarbaz" + xlnt::excel_serializer::central_directory_signature(); - xlnt::string data_b = "bazbarfoo12345678901234567890"; + std::string data_a = "foobarbaz" + xlnt::excel_serializer::central_directory_signature(); + std::string data_b = "bazbarfoo12345678901234567890"; auto f = xlnt::excel_serializer::repair_central_directory(data_a + data_b); TS_ASSERT_EQUALS(f, data_a + data_b.substr(0, 18)); @@ -259,7 +259,7 @@ public: ws.get_cell("A5").set_formula("SUM(A2:A4)"); // Test unicode - xlnt::string expected = "=IF(ISBLANK(B16), \"D\xFCsseldorf\", B16)"; + std::string expected = "=IF(ISBLANK(B16), \"D\xFCsseldorf\", B16)"; TS_ASSERT(ws.get_cell("A16").get_formula() == expected); // Test shared forumlae @@ -365,7 +365,7 @@ public: void test_read_content_types() { - std::vector> expected = + std::vector> expected = { {"/xl/workbook.xml", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"}, {"/xl/worksheets/sheet1.xml", "application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"}, diff --git a/source/serialization/tests/test_style_writer.hpp b/source/serialization/tests/test_style_writer.hpp index 85dc47d0..fdece5ad 100644 --- a/source/serialization/tests/test_style_writer.hpp +++ b/source/serialization/tests/test_style_writer.hpp @@ -15,7 +15,7 @@ public: xlnt::style_serializer writer(wb); xlnt::xml_document observed; writer.write_number_formats(observed.add_child("numFmts")); - xlnt::string expected = + std::string expected = " " " " " "; diff --git a/source/serialization/tests/test_write.hpp b/source/serialization/tests/test_write.hpp index c4d38758..c74b97d1 100644 --- a/source/serialization/tests/test_write.hpp +++ b/source/serialization/tests/test_write.hpp @@ -179,9 +179,9 @@ public: { auto ws = wb_.create_sheet(); ws.get_cell("A1").set_hyperlink("http://test.com"); - TS_ASSERT_EQUALS("http://test.com", ws.get_cell("A1").get_value()); + TS_ASSERT_EQUALS("http://test.com", ws.get_cell("A1").get_value()); ws.get_cell("A1").set_value("test"); - TS_ASSERT_EQUALS("test", ws.get_cell("A1").get_value()); + TS_ASSERT_EQUALS("test", ws.get_cell("A1").get_value()); } void test_write_auto_filter() diff --git a/source/serialization/tests/test_write_workbook.hpp b/source/serialization/tests/test_write_workbook.hpp index bbaee8f9..8d44f124 100644 --- a/source/serialization/tests/test_write_workbook.hpp +++ b/source/serialization/tests/test_write_workbook.hpp @@ -16,7 +16,7 @@ public: xlnt::workbook wb; auto ws = wb.create_sheet(); ws.get_cell("F42").set_value("hello"); - ws.auto_filter("A1:F1"); + ws.get_auto_filter() = "A1:F1"; xlnt::workbook_serializer serializer(wb); auto observed = serializer.write_workbook(); @@ -35,7 +35,7 @@ public: xlnt::workbook_serializer serializer(wb); auto observed = serializer.write_workbook(); - xlnt::string expected_string = + std::string expected_string = "" " " " " @@ -124,7 +124,7 @@ public: auto observed_node = serializer.write_named_ranges(); xlnt::xml_document observed; observed.add_child(observed_node); - xlnt::string expected = + std::string expected = "" "'Sheet'!$A$1:$B$5" ""; @@ -146,7 +146,7 @@ public: xlnt::workbook_serializer serializer(wb); auto observed = serializer.write_workbook(); - xlnt::string expected = + std::string expected = "" " " " " @@ -171,7 +171,7 @@ public: xlnt::xml_document observed; observed.from_string(archive.read("_rels/.rels")); - xlnt::string expected = + std::string expected = "" " " " " diff --git a/source/serialization/theme_serializer.cpp b/source/serialization/theme_serializer.cpp index 97f79b6e..20b34e8c 100644 --- a/source/serialization/theme_serializer.cpp +++ b/source/serialization/theme_serializer.cpp @@ -21,9 +21,9 @@ xml_document theme_serializer::write_theme(const theme &) const struct scheme_element { - string name; - string sub_element_name; - string val; + std::string name; + std::string sub_element_name; + std::string val; }; std::vector scheme_elements = { @@ -53,9 +53,9 @@ xml_document theme_serializer::write_theme(const theme &) const struct font_scheme { bool typeface; - string script; - string major; - string minor; + std::string script; + std::string major; + std::string minor; }; std::vector font_schemes = { diff --git a/source/serialization/workbook_serializer.cpp b/source/serialization/workbook_serializer.cpp index f7892c1b..6494c9e5 100644 --- a/source/serialization/workbook_serializer.cpp +++ b/source/serialization/workbook_serializer.cpp @@ -17,47 +17,38 @@ namespace { -xlnt::datetime w3cdtf_to_datetime(const xlnt::string &string) +xlnt::datetime w3cdtf_to_datetime(const std::string &string) { xlnt::datetime result(1900, 1, 1); - auto separator_index = string.find('-'); - result.year = string.substr(0, separator_index).to(); - result.month = string.substr(separator_index + 1, string.find('-', separator_index + 1)).to(); + result.year = std::stoi(string.substr(0, separator_index)); + result.month = std::stoi(string.substr(separator_index + 1, string.find('-', separator_index + 1))); separator_index = string.find('-', separator_index + 1); - result.day = string.substr(separator_index + 1, string.find('T', separator_index + 1)).to(); + result.day = std::stoi(string.substr(separator_index + 1, string.find('T', separator_index + 1))); separator_index = string.find('T', separator_index + 1); - result.hour = string.substr(separator_index + 1, string.find(':', separator_index + 1)).to(); + result.hour = std::stoi(string.substr(separator_index + 1, string.find(':', separator_index + 1))); separator_index = string.find(':', separator_index + 1); - result.minute = string.substr(separator_index + 1, string.find(':', separator_index + 1)).to(); + result.minute = std::stoi(string.substr(separator_index + 1, string.find(':', separator_index + 1))); separator_index = string.find(':', separator_index + 1); - result.second = string.substr(separator_index + 1, string.find('Z', separator_index + 1)).to(); - + result.second = std::stoi(string.substr(separator_index + 1, string.find('Z', separator_index + 1))); return result; } -xlnt::string fill(const xlnt::string &str, std::size_t length = 2) +std::string fill(const std::string &string, std::size_t length = 2) { - if (str.length() >= length) + if (string.size() >= length) { - return str; + return string; } - xlnt::string result; - - for (std::size_t i = 0; i < length - str.length(); i++) - { - result.append('0'); - } - - return result + str; + return std::string(length - string.size(), '0') + string; } -xlnt::string datetime_to_w3cdtf(const xlnt::datetime &dt) +std::string datetime_to_w3cdtf(const xlnt::datetime &dt) { - return xlnt::string::from(dt.year) + "-" + fill(xlnt::string::from(dt.month)) + "-" + fill(xlnt::string::from(dt.day)) + "T" + - fill(xlnt::string::from(dt.hour)) + ":" + fill(xlnt::string::from(dt.minute)) + ":" + - fill(xlnt::string::from(dt.second)) + "Z"; + return std::to_string(dt.year) + "-" + fill(std::to_string(dt.month)) + "-" + fill(std::to_string(dt.day)) + "T" + + fill(std::to_string(dt.hour)) + ":" + fill(std::to_string(dt.minute)) + ":" + + fill(std::to_string(dt.second)) + "Z"; } } // namespace @@ -85,12 +76,12 @@ void workbook_serializer::read_properties_core(const xml_document &xml) } if (root_node.has_child("dcterms:created")) { - string created_string = root_node.get_child("dcterms:created").get_text(); + std::string created_string = root_node.get_child("dcterms:created").get_text(); props.created = w3cdtf_to_datetime(created_string); } if (root_node.has_child("dcterms:modified")) { - string modified_string = root_node.get_child("dcterms:modified").get_text(); + std::string modified_string = root_node.get_child("dcterms:modified").get_text(); props.modified = w3cdtf_to_datetime(modified_string); } } @@ -149,12 +140,12 @@ xml_document workbook_serializer::write_properties_app() const heading_pairs_vector_node.add_child("vt:variant").add_child("vt:lpstr").set_text("Worksheets"); heading_pairs_vector_node.add_child("vt:variant") .add_child("vt:i4") - .set_text(string::from(workbook_.get_sheet_names().size())); + .set_text(std::to_string(workbook_.get_sheet_names().size())); auto titles_of_parts_node = root_node.add_child("TitlesOfParts"); auto titles_of_parts_vector_node = titles_of_parts_node.add_child("vt:vector"); titles_of_parts_vector_node.add_attribute("baseType", "lpstr"); - titles_of_parts_vector_node.add_attribute("size", string::from(workbook_.get_sheet_names().size())); + titles_of_parts_vector_node.add_attribute("size", std::to_string(workbook_.get_sheet_names().size())); for (auto ws : workbook_) { @@ -220,22 +211,22 @@ xml_document workbook_serializer::write_workbook() const if (relationship.get_type() == relationship::type::worksheet) { // TODO: this is ugly - string sheet_index_string = relationship.get_target_uri(); + std::string sheet_index_string = relationship.get_target_uri(); sheet_index_string = sheet_index_string.substr(0, sheet_index_string.find('.')); sheet_index_string = sheet_index_string.substr(sheet_index_string.find_last_of('/')); auto iter = sheet_index_string.end(); - --iter; + iter--; while (isdigit(*iter)) - --iter; + iter--; auto first_digit = iter - sheet_index_string.begin(); - sheet_index_string = sheet_index_string.substr(static_cast(first_digit + 1)); - std::size_t sheet_index = sheet_index_string.to() - 1; + sheet_index_string = sheet_index_string.substr(static_cast(first_digit + 1)); + std::size_t sheet_index = static_cast(std::stoll(sheet_index_string) - 1); auto ws = workbook_.get_sheet_by_index(sheet_index); auto sheet_node = sheets_node.add_child("sheet"); sheet_node.add_attribute("name", ws.get_title()); - sheet_node.add_attribute("sheetId", string::from(sheet_index + 1)); + sheet_node.add_attribute("sheetId", std::to_string(sheet_index + 1)); sheet_node.add_attribute("r:id", relationship.get_id()); if (ws.has_auto_filter()) @@ -244,7 +235,7 @@ xml_document workbook_serializer::write_workbook() const defined_name_node.add_attribute("name", "_xlnm._FilterDatabase"); defined_name_node.add_attribute("hidden", "1"); defined_name_node.add_attribute("localSheetId", "0"); - string name = + std::string name = "'" + ws.get_title() + "'!" + range_reference::make_absolute(ws.get_auto_filter()).to_string(); defined_name_node.set_text(name); } diff --git a/source/serialization/worksheet_serializer.cpp b/source/serialization/worksheet_serializer.cpp index 929230b1..a1a34ba9 100644 --- a/source/serialization/worksheet_serializer.cpp +++ b/source/serialization/worksheet_serializer.cpp @@ -35,14 +35,14 @@ bool worksheet_serializer::read_worksheet(const xml_document &xml) auto &root_node = xml.get_child("worksheet"); auto &dimension_node = root_node.get_child("dimension"); - string dimension = dimension_node.get_attribute("ref"); + std::string dimension = dimension_node.get_attribute("ref"); auto full_range = xlnt::range_reference(dimension); auto sheet_data_node = root_node.get_child("sheetData"); if (root_node.has_child("mergeCells")) { auto merge_cells_node = root_node.get_child("mergeCells"); - auto count = merge_cells_node.get_attribute("count").to(); + auto count = std::stoull(merge_cells_node.get_attribute("count")); for (auto merge_cell_node : merge_cells_node.get_children()) { @@ -70,23 +70,23 @@ bool worksheet_serializer::read_worksheet(const xml_document &xml) continue; } - auto row_index = row_node.get_attribute("r").to(); + auto row_index = static_cast(std::stoull(row_node.get_attribute("r"))); if (row_node.has_attribute("ht")) { - sheet_.get_row_properties(row_index).height = row_node.get_attribute("ht").to(); + sheet_.get_row_properties(row_index).height = std::stold(row_node.get_attribute("ht")); } - string span_string = row_node.get_attribute("spans"); + std::string span_string = row_node.get_attribute("spans"); auto colon_index = span_string.find(':'); column_t min_column = 0; column_t max_column = 0; - if (colon_index != string::npos) + if (colon_index != std::string::npos) { - min_column = static_cast(span_string.substr(0, colon_index).to()); - max_column = static_cast(span_string.substr(colon_index + 1).to()); + min_column = static_cast(std::stoll(span_string.substr(0, colon_index))); + max_column = static_cast(std::stoll(span_string.substr(colon_index + 1))); } else { @@ -96,7 +96,7 @@ bool worksheet_serializer::read_worksheet(const xml_document &xml) for (column_t i = min_column; i <= max_column; i++) { - string address = i.column_string() + string::from(row_index); + std::string address = i.column_string() + std::to_string(row_index); xml_node cell_node; bool cell_found = false; @@ -119,13 +119,13 @@ bool worksheet_serializer::read_worksheet(const xml_document &xml) if (cell_found) { bool has_value = cell_node.has_child("v"); - string value_string = has_value ? cell_node.get_child("v").get_text() : ""; + std::string value_string = has_value ? cell_node.get_child("v").get_text() : ""; bool has_type = cell_node.has_attribute("t"); - string type = has_type ? cell_node.get_attribute("t") : ""; + std::string type = has_type ? cell_node.get_attribute("t") : ""; bool has_style = cell_node.has_attribute("s"); - auto style_id = static_cast(has_style ? cell_node.get_attribute("s").to() : 0ULL); + auto style_id = static_cast(has_style ? std::stoull(cell_node.get_attribute("s")) : 0LL); bool has_formula = cell_node.has_child("f"); bool has_shared_formula = has_formula && cell_node.get_child("f").has_attribute("t") && @@ -135,18 +135,18 @@ bool worksheet_serializer::read_worksheet(const xml_document &xml) if (has_formula && !has_shared_formula && !sheet_.get_parent().get_data_only()) { - string formula = cell_node.get_child("f").get_text(); + std::string formula = cell_node.get_child("f").get_text(); cell.set_formula(formula); } if (has_type && type == "inlineStr") // inline string { - string inline_string = cell_node.get_child("is").get_child("t").get_text(); + std::string inline_string = cell_node.get_child("is").get_child("t").get_text(); cell.set_value(inline_string); } else if (has_type && type == "s" && !has_formula) // shared string { - auto shared_string_index = value_string.to(); + auto shared_string_index = static_cast(std::stoull(value_string)); auto shared_string = shared_strings.at(shared_string_index); cell.set_value(shared_string); } @@ -166,7 +166,7 @@ bool worksheet_serializer::read_worksheet(const xml_document &xml) } else { - cell.set_value(value_string.to()); + cell.set_value(std::stold(value_string)); } } @@ -187,11 +187,11 @@ bool worksheet_serializer::read_worksheet(const xml_document &xml) continue; } - auto min = static_cast(col_node.get_attribute("min").to()); - auto max = static_cast(col_node.get_attribute("max").to()); - auto width = col_node.get_attribute("width").to(); + auto min = static_cast(std::stoull(col_node.get_attribute("min"))); + auto max = static_cast(std::stoull(col_node.get_attribute("max"))); + auto width = std::stold(col_node.get_attribute("width")); bool custom = col_node.get_attribute("customWidth") == "1"; - auto column_style = static_cast(col_node.has_attribute("style") ? col_node.get_attribute("style").to() : 0ULL); + auto column_style = static_cast(col_node.has_attribute("style") ? std::stoull(col_node.get_attribute("style")) : 0); for (auto column = min; column <= max; column++) { @@ -245,7 +245,7 @@ xml_document worksheet_serializer::write_worksheet() const auto sheet_view_node = sheet_views_node.add_child("sheetView"); sheet_view_node.add_attribute("workbookViewId", "0"); - string active_pane = "bottomRight"; + std::string active_pane = "bottomRight"; if (sheet_.has_frozen_panes()) { @@ -253,13 +253,13 @@ xml_document worksheet_serializer::write_worksheet() const if (sheet_.get_frozen_panes().get_column_index() > 1) { - pane_node.add_attribute("xSplit", string::from(sheet_.get_frozen_panes().get_column_index().index - 1)); + pane_node.add_attribute("xSplit", std::to_string(sheet_.get_frozen_panes().get_column_index().index - 1)); active_pane = "topRight"; } if (sheet_.get_frozen_panes().get_row() > 1) { - pane_node.add_attribute("ySplit", string::from(sheet_.get_frozen_panes().get_row() - 1)); + pane_node.add_attribute("ySplit", std::to_string(sheet_.get_frozen_panes().get_row() - 1)); active_pane = "bottomLeft"; } @@ -295,7 +295,7 @@ xml_document worksheet_serializer::write_worksheet() const } } - string active_cell = "A1"; + std::string active_cell = "A1"; selection_node.add_attribute("activeCell", active_cell); selection_node.add_attribute("sqref", active_cell); @@ -329,15 +329,15 @@ xml_document worksheet_serializer::write_worksheet() const auto col_node = cols_node.add_child("col"); - col_node.add_attribute("min", string::from(column.index)); - col_node.add_attribute("max", string::from(column.index)); - col_node.add_attribute("width", string::from(props.width)); - col_node.add_attribute("style", string::from(props.style)); + col_node.add_attribute("min", std::to_string(column.index)); + col_node.add_attribute("max", std::to_string(column.index)); + col_node.add_attribute("width", std::to_string(props.width)); + col_node.add_attribute("style", std::to_string(props.style)); col_node.add_attribute("customWidth", props.custom ? "1" : "0"); } } - std::unordered_map hyperlink_references; + std::unordered_map hyperlink_references; auto sheet_data_node = root_node.add_child("sheetData"); const auto &shared_strings = sheet_.get_parent().get_shared_strings(); @@ -366,8 +366,8 @@ xml_document worksheet_serializer::write_worksheet() const auto row_node = sheet_data_node.add_child("row"); - row_node.add_attribute("r", string::from(row.front().get_row())); - row_node.add_attribute("spans", (string::from(min) + ":" + string::from(max))); + row_node.add_attribute("r", std::to_string(row.front().get_row())); + row_node.add_attribute("spans", (std::to_string(min) + ":" + std::to_string(max))); if (sheet_.has_row_properties(row.front().get_row())) { @@ -376,11 +376,11 @@ xml_document worksheet_serializer::write_worksheet() const if (height == std::floor(height)) { - row_node.add_attribute("ht", string::from(static_cast(height)) + ".0"); + row_node.add_attribute("ht", std::to_string(static_cast(height)) + ".0"); } else { - row_node.add_attribute("ht", string::from(height)); + row_node.add_attribute("ht", std::to_string(height)); } } @@ -413,7 +413,7 @@ xml_document worksheet_serializer::write_worksheet() const for (std::size_t i = 0; i < shared_strings.size(); i++) { - if (shared_strings[i] == cell.get_value()) + if (shared_strings[i] == cell.get_value()) { match_index = static_cast(i); break; @@ -422,7 +422,7 @@ xml_document worksheet_serializer::write_worksheet() const if (match_index == -1) { - if (cell.get_value().empty()) + if (cell.get_value().empty()) { cell_node.add_attribute("t", "s"); } @@ -430,14 +430,14 @@ xml_document worksheet_serializer::write_worksheet() const { cell_node.add_attribute("t", "inlineStr"); auto inline_string_node = cell_node.add_child("is"); - inline_string_node.add_child("t").set_text(cell.get_value()); + inline_string_node.add_child("t").set_text(cell.get_value()); } } else { cell_node.add_attribute("t", "s"); auto value_node = cell_node.add_child("v"); - value_node.set_text(string::from(match_index)); + value_node.set_text(std::to_string(match_index)); } } else @@ -464,7 +464,7 @@ xml_document worksheet_serializer::write_worksheet() const if (is_integral(cell.get_value())) { - value_node.set_text(string::from(cell.get_value())); + value_node.set_text(std::to_string(cell.get_value())); } else { @@ -472,7 +472,7 @@ xml_document worksheet_serializer::write_worksheet() const ss.precision(20); ss << cell.get_value(); ss.str(); - value_node.set_text(ss.str().data()); + value_node.set_text(ss.str()); } } } @@ -486,7 +486,7 @@ xml_document worksheet_serializer::write_worksheet() const if (cell.has_style()) { - cell_node.add_attribute("s", string::from(cell.get_style_id())); + cell_node.add_attribute("s", std::to_string(cell.get_style_id())); } } } @@ -501,7 +501,7 @@ xml_document worksheet_serializer::write_worksheet() const if (!sheet_.get_merged_ranges().empty()) { auto merge_cells_node = root_node.add_child("mergeCells"); - merge_cells_node.add_attribute("count", string::from(sheet_.get_merged_ranges().size())); + merge_cells_node.add_attribute("count", std::to_string(sheet_.get_merged_ranges().size())); for (auto merged_range : sheet_.get_merged_ranges()) { @@ -535,13 +535,13 @@ xml_document worksheet_serializer::write_worksheet() const auto page_margins_node = root_node.add_child("pageMargins"); //TODO: there must be a better way to do this - auto remove_trailing_zeros = [](const string &n) + auto remove_trailing_zeros = [](const std::string &n) { auto decimal = n.find('.'); - if (decimal == string::npos) return n; + if (decimal == std::string::npos) return n; - auto index = n.length() - 1; + auto index = n.size() - 1; while (index >= decimal && n[index] == '0') { @@ -556,22 +556,22 @@ xml_document worksheet_serializer::write_worksheet() const return n.substr(0, index + 1); }; - page_margins_node.add_attribute("left", remove_trailing_zeros(string::from(sheet_.get_page_margins().get_left()))); - page_margins_node.add_attribute("right", remove_trailing_zeros(string::from(sheet_.get_page_margins().get_right()))); - page_margins_node.add_attribute("top", remove_trailing_zeros(string::from(sheet_.get_page_margins().get_top()))); - page_margins_node.add_attribute("bottom", remove_trailing_zeros(string::from(sheet_.get_page_margins().get_bottom()))); - page_margins_node.add_attribute("header", remove_trailing_zeros(string::from(sheet_.get_page_margins().get_header()))); - page_margins_node.add_attribute("footer", remove_trailing_zeros(string::from(sheet_.get_page_margins().get_footer()))); + page_margins_node.add_attribute("left", remove_trailing_zeros(std::to_string(sheet_.get_page_margins().get_left()))); + page_margins_node.add_attribute("right", remove_trailing_zeros(std::to_string(sheet_.get_page_margins().get_right()))); + page_margins_node.add_attribute("top", remove_trailing_zeros(std::to_string(sheet_.get_page_margins().get_top()))); + page_margins_node.add_attribute("bottom", remove_trailing_zeros(std::to_string(sheet_.get_page_margins().get_bottom()))); + page_margins_node.add_attribute("header", remove_trailing_zeros(std::to_string(sheet_.get_page_margins().get_header()))); + page_margins_node.add_attribute("footer", remove_trailing_zeros(std::to_string(sheet_.get_page_margins().get_footer()))); if (!sheet_.get_page_setup().is_default()) { auto page_setup_node = root_node.add_child("pageSetup"); - string orientation_string = + std::string orientation_string = sheet_.get_page_setup().get_orientation() == page_setup::orientation::landscape ? "landscape" : "portrait"; page_setup_node.add_attribute("orientation", orientation_string); page_setup_node.add_attribute("paperSize", - string::from(static_cast(sheet_.get_page_setup().get_paper_size()))); + std::to_string(static_cast(sheet_.get_page_setup().get_paper_size()))); page_setup_node.add_attribute("fitToHeight", sheet_.get_page_setup().fit_to_height() ? "1" : "0"); page_setup_node.add_attribute("fitToWidth", sheet_.get_page_setup().fit_to_width() ? "1" : "0"); } @@ -580,12 +580,12 @@ xml_document worksheet_serializer::write_worksheet() const { auto header_footer_node = root_node.add_child("headerFooter"); auto odd_header_node = header_footer_node.add_child("oddHeader"); - string header_text = + std::string header_text = "&L&\"Calibri,Regular\"&K000000Left Header Text&C&\"Arial,Regular\"&6&K445566Center Header " "Text&R&\"Arial,Bold\"&8&K112233Right Header Text"; odd_header_node.set_text(header_text); auto odd_footer_node = header_footer_node.add_child("oddFooter"); - string footer_text = + std::string footer_text = "&L&\"Times New Roman,Regular\"&10&K445566Left Footer Text_x000D_And &D and &T&C&\"Times New " "Roman,Bold\"&12&K778899Center Footer Text &Z&F on &A&R&\"Times New Roman,Italic\"&14&KAABBCCRight Footer " "Text &P of &N"; diff --git a/source/serialization/xml_document.cpp b/source/serialization/xml_document.cpp index 06b000b2..893c1dda 100644 --- a/source/serialization/xml_document.cpp +++ b/source/serialization/xml_document.cpp @@ -26,14 +26,14 @@ xml_document::~xml_document() { } -void xml_document::set_encoding(const string &encoding) +void xml_document::set_encoding(const std::string &encoding) { d_->encoding = encoding; } -void xml_document::add_namespace(const string &id, const string &uri) +void xml_document::add_namespace(const std::string &id, const std::string &uri) { - d_->doc.first_child().append_attribute((id.empty() ? "xmlns" : "xmlns:" + id).data()).set_value(uri.data()); + d_->doc.first_child().append_attribute((id.empty() ? "xmlns" : "xmlns:" + id).c_str()).set_value(uri.c_str()); } xml_node xml_document::add_child(const xml_node &child) @@ -42,9 +42,9 @@ xml_node xml_document::add_child(const xml_node &child) return xml_node(detail::xml_node_impl(child_node)); } -xml_node xml_document::add_child(const string &child_name) +xml_node xml_document::add_child(const std::string &child_name) { - auto child = d_->doc.root().append_child(child_name.data()); + auto child = d_->doc.root().append_child(child_name.c_str()); return xml_node(detail::xml_node_impl(child)); } @@ -58,26 +58,26 @@ const xml_node xml_document::get_root() const return xml_node(detail::xml_node_impl(d_->doc.root())); } -string xml_document::to_string() const +std::string xml_document::to_string() const { return xml_serializer::serialize(*this); } -xml_document &xml_document::from_string(const string &xml_string) +xml_document &xml_document::from_string(const std::string &xml_string) { - d_->doc.load(xml_string.data()); + d_->doc.load(xml_string.c_str()); return *this; } -xml_node xml_document::get_child(const string &child_name) +xml_node xml_document::get_child(const std::string &child_name) { - return xml_node(detail::xml_node_impl(d_->doc.child(child_name.data()))); + return xml_node(detail::xml_node_impl(d_->doc.child(child_name.c_str()))); } -const xml_node xml_document::get_child(const string &child_name) const +const xml_node xml_document::get_child(const std::string &child_name) const { - return xml_node(detail::xml_node_impl(d_->doc.child(child_name.data()))); + return xml_node(detail::xml_node_impl(d_->doc.child(child_name.c_str()))); } } // namespace xlnt diff --git a/source/serialization/xml_node.cpp b/source/serialization/xml_node.cpp index 2e65540b..318befe2 100644 --- a/source/serialization/xml_node.cpp +++ b/source/serialization/xml_node.cpp @@ -30,14 +30,14 @@ xml_node &xml_node::operator=(const xlnt::xml_node &other) return *this; } -string xml_node::get_name() const +std::string xml_node::get_name() const { return d_->node.name(); } -void xml_node::set_name(const string &name) +void xml_node::set_name(const std::string &name) { - d_->node.set_name(name.data()); + d_->node.set_name(name.c_str()); } bool xml_node::has_text() const @@ -45,14 +45,14 @@ bool xml_node::has_text() const return d_->node.text() != nullptr; } -string xml_node::get_text() const +std::string xml_node::get_text() const { return d_->node.text().as_string(); } -void xml_node::set_text(const string &text) +void xml_node::set_text(const std::string &text) { - d_->node.text().set(text.data()); + d_->node.text().set(text.c_str()); } const std::vector xml_node::get_children() const @@ -69,7 +69,7 @@ const std::vector xml_node::get_children() const xml_node xml_node::add_child(const xml_node &child) { - auto child_node = xml_node(detail::xml_node_impl(d_->node.append_child(child.get_name().data()))); + auto child_node = xml_node(detail::xml_node_impl(d_->node.append_child(child.get_name().c_str()))); for (auto attr : child.get_attributes()) { @@ -84,9 +84,9 @@ xml_node xml_node::add_child(const xml_node &child) return child_node; } -xml_node xml_node::add_child(const string &child_name) +xml_node xml_node::add_child(const std::string &child_name) { - return xml_node(detail::xml_node_impl(d_->node.append_child(child_name.data()))); + return xml_node(detail::xml_node_impl(d_->node.append_child(child_name.c_str()))); } const std::vector xml_node::get_attributes() const @@ -95,43 +95,43 @@ const std::vector xml_node::get_attributes() const for (auto attr : d_->node.attributes()) { - attributes.push_back(std::make_pair(attr.name(), attr.value())); + attributes.push_back(std::make_pair(attr.name(), attr.value())); } return attributes; } -void xml_node::add_attribute(const string &name, const string &value) +void xml_node::add_attribute(const std::string &name, const std::string &value) { - d_->node.append_attribute(name.data()).set_value(value.data()); + d_->node.append_attribute(name.c_str()).set_value(value.c_str()); } -bool xml_node::has_attribute(const string &attribute_name) const +bool xml_node::has_attribute(const std::string &attribute_name) const { - return d_->node.attribute(attribute_name.data()) != nullptr; + return d_->node.attribute(attribute_name.c_str()) != nullptr; } -string xml_node::get_attribute(const string &attribute_name) const +std::string xml_node::get_attribute(const std::string &attribute_name) const { - return d_->node.attribute(attribute_name.data()).value(); + return d_->node.attribute(attribute_name.c_str()).value(); } -bool xml_node::has_child(const string &child_name) const +bool xml_node::has_child(const std::string &child_name) const { - return d_->node.child(child_name.data()) != nullptr; + return d_->node.child(child_name.c_str()) != nullptr; } -xml_node xml_node::get_child(const string &child_name) +xml_node xml_node::get_child(const std::string &child_name) { - return xml_node(detail::xml_node_impl(d_->node.child(child_name.data()))); + return xml_node(detail::xml_node_impl(d_->node.child(child_name.c_str()))); } -const xml_node xml_node::get_child(const string &child_name) const +const xml_node xml_node::get_child(const std::string &child_name) const { - return xml_node(detail::xml_node_impl(d_->node.child(child_name.data()))); + return xml_node(detail::xml_node_impl(d_->node.child(child_name.c_str()))); } -string xml_node::to_string() const +std::string xml_node::to_string() const { return xml_serializer::serialize_node(*this); } diff --git a/source/serialization/xml_serializer.cpp b/source/serialization/xml_serializer.cpp index 7f32bed8..bc12e5a7 100644 --- a/source/serialization/xml_serializer.cpp +++ b/source/serialization/xml_serializer.cpp @@ -10,23 +10,23 @@ namespace xlnt { -string xml_serializer::serialize(const xml_document &xml) +std::string xml_serializer::serialize(const xml_document &xml) { std::ostringstream ss; xml.d_->doc.save(ss, " ", pugi::format_default, pugi::encoding_utf8); - return ss.str().data(); + return ss.str(); } -xml_document xml_serializer::deserialize(const string &xml_string) +xml_document xml_serializer::deserialize(const std::string &xml_string) { xml_document doc; - doc.d_->doc.load(xml_string.data()); + doc.d_->doc.load(xml_string.c_str()); return doc; } -string xml_serializer::serialize_node(const xml_node &xml) +std::string xml_serializer::serialize_node(const xml_node &xml) { pugi::xml_document doc; doc.append_copy(xml.d_->node); @@ -34,7 +34,7 @@ string xml_serializer::serialize_node(const xml_node &xml) std::ostringstream ss; doc.save(ss); - return ss.str().data(); + return ss.str(); } } // namespace xlnt diff --git a/source/styles/number_format.cpp b/source/styles/number_format.cpp index f390b049..18edd7cc 100644 --- a/source/styles/number_format.cpp +++ b/source/styles/number_format.cpp @@ -6,10 +6,10 @@ namespace { -const std::unordered_map &builtin_formats() +const std::unordered_map &builtin_formats() { - static const std::unordered_map *formats = - new std::unordered_map + static const std::unordered_map *formats = + new std::unordered_map ({ { 0, "General" }, { 1, "0" }, @@ -281,12 +281,12 @@ number_format::number_format(std::size_t id) : number_format(from_builtin_id(id) { } -number_format::number_format(const string &format_string) : id_set_(false), id_(0) +number_format::number_format(const std::string &format_string) : id_set_(false), id_(0) { set_format_string(format_string); } -number_format::number_format(const string &format_string, std::size_t id) : id_set_(false), id_(0) +number_format::number_format(const std::string &format_string, std::size_t id) : id_set_(false), id_(0) { set_format_string(format_string, id); } @@ -295,14 +295,14 @@ number_format number_format::from_builtin_id(std::size_t builtin_id) { if (builtin_formats().find(builtin_id) == builtin_formats().end()) { - throw std::runtime_error(("unknown id: " + string::from(builtin_id)).data()); + throw std::runtime_error("unknown id: " + std::to_string(builtin_id)); } auto format_string = builtin_formats().at(builtin_id); return number_format(format_string, builtin_id); } -string number_format::get_format_string() const +std::string number_format::get_format_string() const { return format_string_; } @@ -316,7 +316,7 @@ std::size_t number_format::hash() const } -void number_format::set_format_string(const string &format_string) +void number_format::set_format_string(const std::string &format_string) { format_string_ = format_string; id_ = 0; @@ -333,7 +333,7 @@ void number_format::set_format_string(const string &format_string) } } -void number_format::set_format_string(const string &format_string, std::size_t id) +void number_format::set_format_string(const std::string &format_string, std::size_t id) { format_string_ = format_string; id_ = id; diff --git a/source/utils/datetime.cpp b/source/utils/datetime.cpp index 13950d4b..ac986edb 100644 --- a/source/utils/datetime.cpp +++ b/source/utils/datetime.cpp @@ -119,20 +119,20 @@ bool datetime::operator==(const datetime &comparand) const minute == comparand.minute && second == comparand.second && microsecond == comparand.microsecond; } -time::time(const string &time_string) : hour(0), minute(0), second(0), microsecond(0) +time::time(const std::string &time_string) : hour(0), minute(0), second(0), microsecond(0) { - string remaining = time_string; + std::string remaining = time_string; auto colon_index = remaining.find(':'); - hour = remaining.substr(0, colon_index).to(); + hour = std::stoi(remaining.substr(0, colon_index)); remaining = remaining.substr(colon_index + 1); colon_index = remaining.find(':'); - minute = remaining.substr(0, colon_index).to(); + minute = std::stoi(remaining.substr(0, colon_index)); colon_index = remaining.find(':'); - if (colon_index != string::npos) + if (colon_index != std::string::npos) { remaining = remaining.substr(colon_index + 1); - second = remaining.to(); + second = std::stoi(remaining); } } @@ -179,10 +179,10 @@ long double datetime::to_number(calendar base_date) const return date(year, month, day).to_number(base_date) + time(hour, minute, second, microsecond).to_number(); } -string datetime::to_string(xlnt::calendar /*base_date*/) const +std::string datetime::to_string(xlnt::calendar /*base_date*/) const { - return string::from(year) + "/" + string::from(month) + "/" + string::from(day) + " " + string::from(hour) + - ":" + string::from(minute) + ":" + string::from(second) + ":" + string::from(microsecond); + return std::to_string(year) + "/" + std::to_string(month) + "/" + std::to_string(day) + " " + std::to_string(hour) + + ":" + std::to_string(minute) + ":" + std::to_string(second) + ":" + std::to_string(microsecond); } date date::today() diff --git a/source/utils/exceptions.cpp b/source/utils/exceptions.cpp index 0ab9f334..27ce002b 100644 --- a/source/utils/exceptions.cpp +++ b/source/utils/exceptions.cpp @@ -2,39 +2,46 @@ namespace xlnt { -sheet_title_exception::sheet_title_exception(const string &title) +sheet_title_exception::sheet_title_exception(const std::string &title) + : std::runtime_error(std::string("bad worksheet title: ") + title) { } -column_string_index_exception::column_string_index_exception() +column_string_index_exception::column_string_index_exception() : std::runtime_error("") { } -data_type_exception::data_type_exception() +data_type_exception::data_type_exception() : std::runtime_error("") { } -attribute_error::attribute_error() +attribute_error::attribute_error() : std::runtime_error("") { } named_range_exception::named_range_exception() + : std::runtime_error("named range not found or not owned by this worksheet") { } -invalid_file_exception::invalid_file_exception(const string &filename) +invalid_file_exception::invalid_file_exception(const std::string &filename) + : std::runtime_error(std::string("couldn't open file: (") + filename + ")") { } cell_coordinates_exception::cell_coordinates_exception(column_t column, row_t row) + : std::runtime_error(std::string("bad cell coordinates: (") + std::to_string(column.index) + ", " + std::to_string(row) + + ")") { } -cell_coordinates_exception::cell_coordinates_exception(const string &coord_string) +cell_coordinates_exception::cell_coordinates_exception(const std::string &coord_string) + : std::runtime_error(std::string("bad cell coordinates: (") + (coord_string.empty() ? "" : coord_string) + ")") { } -illegal_character_error::illegal_character_error(xlnt::utf32_char c) +illegal_character_error::illegal_character_error(char c) + : std::runtime_error(std::string("illegal character: (") + std::to_string(static_cast(c)) + ")") { } diff --git a/source/utils/string.cpp b/source/utils/string.cpp deleted file mode 100644 index 822ec981..00000000 --- a/source/utils/string.cpp +++ /dev/null @@ -1,930 +0,0 @@ -#include -#include -#include -#include -#include -#include -//TODO: make this conditional on XLNT_STD_STRING once std::sto* functions are replaced -#include -#include - -#include - -#include - -namespace { - -template -std::size_t string_length(const T *arr) -{ - std::size_t i = 0; - - while (arr[i] != T(0)) - { - i++; - } - - return i; -} - -xlnt::string::code_point to_upper(xlnt::string::code_point p) -{ - if(p >= U'a' && p <= U'z') - { - return U'A' + p - U'a'; - } - - return p; -} - -xlnt::string::code_point to_lower(xlnt::string::code_point p) -{ - if(p >= U'A' && p <= U'Z') - { - return U'a' + p - U'A'; - } - - return p; -} - -} - -namespace xlnt { - -template<> -string string::from(std::int8_t i) -{ - return string(std::to_string(i).c_str()); -} - -template<> -string string::from(std::int16_t i) -{ - return string(std::to_string(i).c_str()); -} - -template<> -string string::from(std::int32_t i) -{ - return string(std::to_string(i).c_str()); -} - -template<> -string string::from(std::int64_t i) -{ - return string(std::to_string(i).c_str()); -} - -template<> -string string::from(std::uint8_t i) -{ - return string(std::to_string(i).c_str()); -} - -template<> -string string::from(std::uint16_t i) -{ - return string(std::to_string(i).c_str()); -} - -template<> -string string::from(std::uint32_t i) -{ - return string(std::to_string(i).c_str()); -} - -template<> -string string::from(std::uint64_t i) -{ - return string(std::to_string(i).c_str()); -} - -template<> -string string::from(float i) -{ - return string(std::to_string(i).c_str()); -} - -template<> -string string::from(double i) -{ - return string(std::to_string(i).c_str()); -} - -template<> -string string::from(long double i) -{ - return string(std::to_string(i).c_str()); -} - -xlnt::string::iterator::iterator(xlnt::string *parent, size_type index) - : parent_(parent), - index_(index) -{ -} - -xlnt::string::iterator::iterator(const xlnt::string::iterator &other) - : parent_(other.parent_), - index_(other.index_) -{ -} - -string::code_point xlnt::string::iterator::operator*() -{ - return parent_->at(index_); -} - -bool xlnt::string::iterator::operator==(const iterator &other) const -{ - return parent_ == other.parent_ && index_ == other.index_; -} - -string::difference_type string::iterator::operator-(const iterator &other) const -{ - return index_ - other.index_; -} - -xlnt::string::const_iterator::const_iterator(const xlnt::string *parent, size_type index) - : parent_(parent), - index_(index) -{ -} - -xlnt::string::const_iterator::const_iterator(const xlnt::string::iterator &other) - : parent_(other.parent_), - index_(other.index_) -{ -} - -xlnt::string::const_iterator::const_iterator(const xlnt::string::const_iterator &other) - : parent_(other.parent_), - index_(other.index_) -{ -} - -string::difference_type string::const_iterator::operator-(const const_iterator &other) const -{ - return index_ - other.index_; -} - -const string::code_point xlnt::string::const_iterator::operator*() const -{ - return parent_->at(index_); -} - -bool xlnt::string::const_iterator::operator==(const const_iterator &other) const -{ - return parent_ == other.parent_ && index_ == other.index_; -} - -xlnt::string::iterator &xlnt::string::iterator::operator--() -{ - return *this -= 1; -} - -xlnt::string::const_iterator &xlnt::string::const_iterator::operator--() -{ - return *this -= 1; -} - -xlnt::string::iterator &xlnt::string::iterator::operator++() -{ - return *this += 1; -} - -xlnt::string::const_iterator &xlnt::string::const_iterator::operator++() -{ - return *this += 1; -} - -string::const_iterator &string::const_iterator::operator+=(int offset) -{ - auto new_index = static_cast(index_) + offset; - new_index = std::max(0, std::min(static_cast(parent_->length()), new_index)); - index_ = static_cast(new_index); - - return *this; -} - -xlnt::string::iterator xlnt::string::iterator::operator+(int offset) -{ - iterator copy = *this; - - auto new_index = static_cast(index_) + offset; - new_index = std::max(0, std::min(static_cast(parent_->length()), new_index)); - copy.index_ = static_cast(new_index); - - return copy; -} - -xlnt::string::const_iterator xlnt::string::const_iterator::operator+(int offset) -{ - const_iterator copy = *this; - - auto new_index = static_cast(index_) + offset; - new_index = std::max(0, std::min(static_cast(parent_->length()), new_index)); - copy.index_ = static_cast(new_index); - - return copy; -} - -string::string(size_type initial_size) - : data_(new std::vector), - code_point_byte_offsets_(new std::unordered_map) -{ - data_->resize(initial_size + 1); - data_->back() = '\0'; - - code_point_byte_offsets_->insert({0, 0}); -} - -string::string() : string(size_type(0)) -{ -} - -string::string(string &&str) : string() -{ - swap(*this, str); -} - -string::string(const string &str) - : data_(new std::vector(*str.data_)), - code_point_byte_offsets_(new std::unordered_map(*str.code_point_byte_offsets_)) -{ -} - -string::string(const string &str, size_type offset) : string(str, offset, str.length() - offset) -{ -} - -string::string(const string &str, size_type offset, size_type len) : string() -{ - auto part = str.substr(offset, len); - - *data_ = *part.data_; - *code_point_byte_offsets_ = *part.code_point_byte_offsets_; -} - -string::string(const utf_mb_wide_string str) : string() -{ - auto iter = str; - - while(*iter != '\0') - { - append(*iter); - iter++; - } -} - -string::string(const utf8_string str) : string() -{ - auto start = str; - auto end = str; - - while(*end != '\0') - { - ++end; - } - - auto iter = start; - - while(iter != end) - { - append((utf32_char)utf8::next(iter, end)); - } -} - -string::string(const utf16_string str) : string() -{ - auto iter = str; - - while(*iter != '\0') - { - append(*iter); - iter++; - } -} - -string::string(const utf32_string str) : string() -{ -auto iter = str; - - while(*iter != '\0') - { - append(*iter); - iter++; - } -} - -string::~string() -{ - delete data_; - data_ = nullptr; - delete code_point_byte_offsets_; - code_point_byte_offsets_ = nullptr; -} - -string string::to_upper() const -{ - string upper; - - for(auto c : *this) - { - upper.append(::to_upper(c)); - } - - return upper; -} - -string string::to_lower() const -{ - - string lower; - - for(auto c : *this) - { - lower.append(::to_lower(c)); - } - - return lower; -} - -string string::substr(size_type offset) const -{ - return substr(offset, length() - offset); -} - -string string::substr(size_type offset, size_type len) const -{ - if(len != npos && offset + len < length()) - { - return string(begin() + static_cast(offset), begin() + static_cast(offset + len)); - } - - return string(begin() + static_cast(offset), end()); -} - -string::code_point string::back() const -{ - return at(length() - 1); -} - -string::code_point string::front() const -{ - return at(0); -} - -string::size_type string::find(code_point c) const -{ - return find(c, 0); -} - -string::size_type string::find(char c) const -{ - return find(c, 0); -} - -string::size_type string::find(const string &str) const -{ - return find(str, 0); -} - -string::size_type string::find(code_point c, size_type offset) const -{ - auto iter = begin() + static_cast(offset); - - while (iter != end()) - { - if (*iter == c) - { - return offset; - } - - ++iter; - offset++; - } - - return npos; -} - -string::size_type string::find(char c, size_type offset) const -{ - return find(static_cast(c), offset); -} - -string::size_type string::find(const string &str, size_type offset) const -{ - while (offset < length() - str.length()) - { - if (substr(offset, str.length()) == str) - { - return offset; - } - - offset++; - } - - return npos; -} - -string::size_type string::find_last_of(code_point c) const -{ - return find_last_of(c, 0); -} - -string::size_type string::find_last_of(char c) const -{ - return find_last_of(c, 0); -} - -string::size_type string::find_last_of(const string &str) const -{ - return find_last_of(str, 0); -} - -string::size_type string::find_last_of(code_point c, size_type offset) const -{ - auto stop = begin() + static_cast(offset); - auto iter = end() - 1; - - while (iter != stop) - { - if (*iter == c) - { - return iter - begin(); - } - - --iter; - } - - return *stop == c ? offset : npos; -} -string::size_type string::find_last_of(char c, size_type offset) const -{ - return find_last_of(static_cast(c), offset); -} - -string::size_type string::find_last_of(const string &str, size_type offset) const -{ - auto stop = begin() + static_cast(offset); - auto iter = end() - 1; - - while (iter != stop) - { - if(str.find(*iter) != npos) - { - return iter - begin(); - } - - --iter; - } - - return npos; -} - -string::size_type string::find_first_of(const string &str) const -{ - return find_first_of(str, 0); -} - -string::size_type string::find_first_of(const string &str, size_type offset) const -{ - auto iter = begin() + static_cast(offset); - - while (iter != end()) - { - if(str.find(*iter) != npos) - { - return iter - begin(); - } - - ++iter; - } - - return npos; -} - -string::size_type string::find_first_not_of(const string &str) const -{ - return find_first_not_of(str, 0); -} - -string::size_type string::find_first_not_of(const string &str, size_type offset) const -{ - auto iter = begin() + static_cast(offset); - - while (iter != end()) - { - if(str.find(*iter) == npos) - { - return iter - begin(); - } - - ++iter; - } - - return npos; -} - -string::size_type string::find_last_not_of(const string &str) const -{ - return find_last_not_of(str, 0); -} - -string::size_type string::find_last_not_of(const string &str, size_type offset) const -{ - auto stop = begin() + static_cast(offset); - auto iter = end() - 1; - - while (iter != stop) - { - if(str.find(*iter) == npos) - { - return iter - begin(); - } - - --iter; - } - - return npos; -} - -void string::clear() -{ - data_->clear(); - data_->push_back('\0'); - code_point_byte_offsets_->clear(); - code_point_byte_offsets_->insert({0, 0}); -} - -template<> -std::size_t string::to() const -{ - return std::stoull(std::string(data())); -} - -template<> -std::uint32_t string::to() const -{ - return std::stoul(std::string(data())); -} - -template<> -std::int32_t string::to() const -{ - return std::stoi(std::string(data())); -} - -template<> -long double string::to() const -{ - return std::stold(std::string(data())); -} - -template<> -double string::to() const -{ - return std::stod(std::string(data())); -} - -#ifdef XLNT_STD_STRING -string::string(const std::string &str) : string(str.data()) -{ -} - -template<> -std::string string::to() const -{ - return std::string(data()); -} -#endif - -int string::to_hex() const -{ - return 0; -} - -void string::erase(size_type index) -{ - auto start = code_point_byte_offsets_->at(index); - auto next_start = code_point_byte_offsets_->at(index + 1); - - data_->erase(data_->begin() + start, data_->begin() + next_start); - - auto code_point_bytes = next_start - start; - - for(size_type i = index + 1; i < length(); i++) - { - code_point_byte_offsets_->at(i) = code_point_byte_offsets_->at(i + 1) - code_point_bytes; - } - - code_point_byte_offsets_->erase(code_point_byte_offsets_->find(length())); -} - -string &string::operator=(string rhs) -{ - swap(*this, rhs); - - return *this; -} - -string::iterator string::begin() -{ - return iterator(this, 0); -} - -string::const_iterator string::cbegin() const -{ - return const_iterator(this, 0); -} - -string::iterator string::end() -{ - return iterator(this, length()); -} - -string::const_iterator string::cend() const -{ - return const_iterator(this, length()); -} - -string::byte_pointer string::data() -{ - return &data_->front(); -} - -string::const_byte_pointer string::data() const -{ - return &data_->front(); -} - -std::size_t string::hash() const -{ - static std::hash hasher; - return hasher(std::string(data())); -} - -std::size_t string::num_bytes() const -{ - return data_->size(); -} - -void string::append(char c) -{ - data_->back() = c; - data_->push_back('\0'); - - code_point_byte_offsets_->insert({length() + 1, num_bytes() - 1}); -} - -void string::append(wchar_t c) -{ - if(c < 128) - { - append(static_cast(c)); - return; - } - - data_->pop_back(); - - std::array utf8_encoded {{0}}; - auto end = utf8::utf16to8(&c, &c + 1, utf8_encoded.begin()); - std::copy(utf8_encoded.begin(), end, std::back_inserter(*data_)); - - data_->push_back('\0'); - - code_point_byte_offsets_->insert({length() + 1, num_bytes() - 1}); -} - -void string::append(char16_t c) -{ - if(c < 128) - { - append(static_cast(c)); - return; - } - - data_->pop_back(); - - std::array utf8_encoded {{0}}; - auto end = utf8::utf16to8(&c, &c + 1, utf8_encoded.begin()); - std::copy(utf8_encoded.begin(), end, std::back_inserter(*data_)); - - data_->push_back('\0'); - - code_point_byte_offsets_->insert({length() + 1, num_bytes() - 1}); -} - -void string::append(code_point c) -{ - if(c < 128) - { - append(static_cast(c)); - return; - } - - data_->pop_back(); - - std::array utf8_encoded {{0}}; - auto end = utf8::utf32to8(&c, &c + 1, utf8_encoded.begin()); - std::copy(utf8_encoded.begin(), end, std::back_inserter(*data_)); - - data_->push_back('\0'); - - code_point_byte_offsets_->insert({length() + 1, num_bytes() - 1}); -} - -void string::append(const string &str) -{ - for (auto c : str) - { - append(c); - } -} - -void string::replace(size_type index, utf32_char value) -{ - std::array encoded = {{0}}; - auto encoded_end = utf8::utf32to8(&value, &value + 1, encoded.begin()); - auto encoded_len = encoded_end - encoded.begin(); - - auto data_start = code_point_byte_offsets_->at(index); - auto data_end = code_point_byte_offsets_->at(index + 1); - - auto previous_len = static_cast(data_end - data_start); - int difference = static_cast(encoded_len) - previous_len; - - if(difference < 0) - { - data_->erase(data_->begin() + data_end + difference, data_->begin() + data_end); - } - else if(difference > 0) - { - data_->insert(data_->begin() + data_start, difference, '\0'); - } - - for(std::size_t i = index + 1; i < code_point_byte_offsets_->size(); i++) - { - code_point_byte_offsets_->at(i) += difference; - } - - auto iter = encoded.begin(); - auto data_iter = data_->begin() + data_start; - - while(iter != encoded_end) - { - *data_iter = *iter; - ++data_iter; - ++iter; - } -} - -string::code_point string::at(size_type index) -{ - if(index == length()) - { - return U'\0'; - } - - return utf8::peek_next(data_->begin() + code_point_byte_offsets_->at(index), data_->end()); -} - -const string::code_point string::at(size_type index) const -{ - if(index == length()) - { - return U'\0'; - } - - return utf8::peek_next(data_->begin() + code_point_byte_offsets_->at(index), data_->end()); -} - -bool string::operator==(const_byte_pointer str) const -{ - return *this == string(str); -} - -bool string::operator==(const string &str) const -{ - if (length() != str.length()) return false; - - auto left_iter = begin(); - auto right_iter = str.begin(); - - while (left_iter != end() && right_iter != str.end()) - { - if (*left_iter != *right_iter) - { - return false; - } - - ++left_iter; - ++right_iter; - } - - return (left_iter == end()) != (right_iter == end()); -} - -string::code_point string::operator[](size_type index) -{ - return at(index); -} - -const string::code_point string::operator[](size_type index) const -{ - return at(index); -} - -string string::operator+(const string &rhs) const -{ - string copy(*this); - copy.append(rhs); - - return copy; -} - -string &string::operator+=(const string &rhs) -{ - append(rhs); - - return *this; -} - -XLNT_FUNCTION void swap(string &left, string &right) -{ - using std::swap; - - swap(left.data_, right.data_); - swap(left.code_point_byte_offsets_, right.code_point_byte_offsets_); -} - -XLNT_FUNCTION std::ostream &operator<<(std::ostream &left, string &right) -{ - auto d = right.data(); - std::size_t i = 0; - - while (d[i] != '\0') - { - left << d[i]; - i++; - } - - return left; -} - -XLNT_FUNCTION string operator+(const char *left, const string &right) -{ - return string(left) + right; -} - -XLNT_FUNCTION bool string::operator<(const string &other) const -{ - return std::string(data()) < std::string(other.data()); -} - -string::size_type string::length() const -{ - return code_point_byte_offsets_->size() - 1; -} - -#ifdef _MSC_VER -template<> -string string::from(unsigned long i) -{ - return string(std::to_string(i).c_str()); -} - -template<> -unsigned long string::to() const -{ - return std::stoul(std::string(data())); -} -#endif - -#ifdef __linux -template<> -string string::from(long long int i) -{ - return string(std::to_string(i).c_str()); -} - -template<> -string string::from(unsigned long long int i) -{ - return string(std::to_string(i).c_str()); -} - -template<> -long long int string::to() const -{ - return std::stoll(std::string(data())); -} - -template<> -unsigned long long int string::to() const -{ - return std::stoull(std::string(data())); -} -#endif - -} // namespace xlnt diff --git a/source/utils/tests/test_zip_file.hpp b/source/utils/tests/test_zip_file.hpp index ccc2fda5..06db3807 100644 --- a/source/utils/tests/test_zip_file.hpp +++ b/source/utils/tests/test_zip_file.hpp @@ -19,7 +19,7 @@ public: void remove_temp_file() { - std::remove(temp_file.GetFilename().data()); + std::remove(temp_file.GetFilename().c_str()); } void make_temp_directory() @@ -30,14 +30,14 @@ public: { } - bool files_equal(const xlnt::string &a, const xlnt::string &b) + bool files_equal(const std::string &a, const std::string &b) { if(a == b) { return true; } - std::ifstream stream_a(a.data(), std::ios::binary), stream_b(a.data(), std::ios::binary); + std::ifstream stream_a(a, std::ios::binary), stream_b(a, std::ios::binary); while(stream_a && stream_b) { @@ -63,9 +63,9 @@ public: { remove_temp_file(); { - std::ifstream in_stream(existing_file.data(), std::ios::binary); + std::ifstream in_stream(existing_file, std::ios::binary); xlnt::zip_file f(in_stream); - std::ofstream out_stream(temp_file.GetFilename().data(), std::ios::binary); + std::ofstream out_stream(temp_file.GetFilename(), std::ios::binary); f.save(out_stream); } TS_ASSERT(files_equal(existing_file, temp_file.GetFilename())); @@ -78,7 +78,7 @@ public: xlnt::zip_file f; std::vector source_bytes, result_bytes; - std::ifstream in_stream(existing_file.data(), std::ios::binary); + std::ifstream in_stream(existing_file, std::ios::binary); while(in_stream) { source_bytes.push_back((unsigned char)in_stream.get()); @@ -149,7 +149,7 @@ public: xlnt::zip_file f(existing_file); std::stringstream ss; ss << f.open("[Content_Types].xml").rdbuf(); - xlnt::string result = ss.str().c_str(); + std::string result = ss.str(); TS_ASSERT(result == expected_content_types_string); } @@ -158,7 +158,7 @@ public: xlnt::zip_file f(existing_file); std::stringstream ss; ss << f.open("[Content_Types].xml").rdbuf(); - xlnt::string result = ss.str().data(); + std::string result = ss.str(); TS_ASSERT(result == expected_content_types_string); } @@ -197,7 +197,7 @@ public: xlnt::zip_file f(existing_file); std::stringstream ss; f.printdir(ss); - xlnt::string printed = ss.str().data(); + auto printed = ss.str(); TS_ASSERT(printed == expected_printdir_string); } @@ -232,7 +232,7 @@ public: { TS_ASSERT(f2.read(info) == expected_atxt_string); } - else if(info.filename.substr(info.filename.length() - 17) == "sharedStrings.xml") + else if(info.filename.substr(info.filename.size() - 17) == "sharedStrings.xml") { TS_ASSERT(f2.read(info) == expected_atxt_string); } @@ -276,8 +276,8 @@ public: private: TemporaryFile temp_file; - xlnt::string existing_file; - xlnt::string expected_content_types_string; - xlnt::string expected_atxt_string; - xlnt::string expected_printdir_string; + std::string existing_file; + std::string expected_content_types_string; + std::string expected_atxt_string; + std::string expected_printdir_string; }; diff --git a/source/workbook/named_range.cpp b/source/workbook/named_range.cpp index ed744fa4..2fa5b9a2 100644 --- a/source/workbook/named_range.cpp +++ b/source/workbook/named_range.cpp @@ -12,13 +12,13 @@ namespace { /// /// This should maybe be in a utility header so it can be used elsewhere. /// -std::vector split_string(const xlnt::string &string, char delim) +std::vector split_string(const std::string &string, char delim) { - std::vector split; - xlnt::string::size_type previous_index = 0; + std::vector split; + std::string::size_type previous_index = 0; auto separator_index = string.find(delim); - while (separator_index != xlnt::string::npos) + while (separator_index != std::string::npos) { auto part = string.substr(previous_index, separator_index - previous_index); split.push_back(part); @@ -27,8 +27,7 @@ std::vector split_string(const xlnt::string &string, char delim) separator_index = string.find(delim, previous_index); } - auto part = string.substr(previous_index); - split.push_back(part); + split.push_back(string.substr(previous_index)); return split; } @@ -37,9 +36,9 @@ std::vector split_string(const xlnt::string &string, char delim) namespace xlnt { -std::vector> split_named_range(const string &named_range_string) +std::vector> split_named_range(const std::string &named_range_string) { - std::vector> final; + std::vector> final; for (auto part : split_string(named_range_string, ',')) { @@ -75,7 +74,7 @@ named_range::named_range(const named_range &other) *this = other; } -named_range::named_range(const string &name, const std::vector &targets) +named_range::named_range(const std::string &name, const std::vector &targets) : name_(name), targets_(targets) { } diff --git a/source/workbook/tests/test_named_range.hpp b/source/workbook/tests/test_named_range.hpp index 444fb359..0c17a8b2 100644 --- a/source/workbook/tests/test_named_range.hpp +++ b/source/workbook/tests/test_named_range.hpp @@ -10,9 +10,9 @@ class test_named_range : public CxxTest::TestSuite public: void test_split() { - using string_pair = std::pair; + using string_pair = std::pair; using string_pair_vector = std::vector; - using expected_pair = std::pair; + using expected_pair = std::pair; std::vector expected_pairs = { diff --git a/source/workbook/tests/test_workbook.hpp b/source/workbook/tests/test_workbook.hpp index d0f780de..e07b0901 100644 --- a/source/workbook/tests/test_workbook.hpp +++ b/source/workbook/tests/test_workbook.hpp @@ -47,7 +47,7 @@ public: { xlnt::workbook wb; auto new_sheet = wb.create_sheet(); - xlnt::string title = "my sheet"; + std::string title = "my sheet"; new_sheet.set_title(title); auto found_sheet = wb.get_sheet_by_name(title); TS_ASSERT_EQUALS(new_sheet, found_sheet); @@ -58,8 +58,8 @@ public: xlnt::workbook wb; auto new_sheet = wb.create_sheet(); std::string title = "my sheet"; - new_sheet.set_title(title.c_str()); - auto found_sheet = wb.get_sheet_by_name(title.c_str()); + new_sheet.set_title(title); + auto found_sheet = wb.get_sheet_by_name(title); TS_ASSERT_EQUALS(new_sheet, found_sheet); TS_ASSERT_EQUALS(wb.get_sheet_by_name("NotThere"), nullptr); @@ -78,7 +78,7 @@ public: xlnt::workbook wb; wb.clear(); - std::vector names = {"NewSheet", "NewSheet1", "NewSheet2", "NewSheet3", "NewSheet4", "NewSheet5"}; + std::vector names = {"NewSheet", "NewSheet1", "NewSheet2", "NewSheet3", "NewSheet4", "NewSheet5"}; for(std::size_t count = 0; count < names.size(); count++) { @@ -120,7 +120,7 @@ public: { xlnt::workbook wb; auto new_sheet = wb.create_sheet(); - xlnt::string title = "my sheet"; + std::string title = "my sheet"; new_sheet.set_title(title); auto found_sheet = wb.get_sheet_by_name(title); TS_ASSERT_EQUALS(new_sheet, found_sheet); diff --git a/source/workbook/workbook.cpp b/source/workbook/workbook.cpp index 2711f73f..dc5a8929 100644 --- a/source/workbook/workbook.cpp +++ b/source/workbook/workbook.cpp @@ -122,7 +122,7 @@ bool workbook::const_iterator::operator==(const const_iterator &comparand) const return index_ == comparand.index_ && wb_ == comparand.wb_; } -worksheet workbook::get_sheet_by_name(const string &name) +worksheet workbook::get_sheet_by_name(const std::string &name) { for (auto &impl : d_->worksheets_) { @@ -150,7 +150,7 @@ worksheet workbook::get_active_sheet() return worksheet(&d_->worksheets_[d_->active_sheet_index_]); } -bool workbook::has_named_range(const string &name) const +bool workbook::has_named_range(const std::string &name) const { for (auto worksheet : *this) { @@ -164,18 +164,18 @@ bool workbook::has_named_range(const string &name) const worksheet workbook::create_sheet() { - string title = "Sheet1"; + std::string title = "Sheet1"; int index = 1; while (get_sheet_by_name(title) != nullptr) { - title = "Sheet" + string::from(++index); + title = "Sheet" + std::to_string(++index); } - string sheet_filename = "worksheets/sheet" + string::from(d_->worksheets_.size() + 1) + ".xml"; + std::string sheet_filename = "worksheets/sheet" + std::to_string(d_->worksheets_.size() + 1) + ".xml"; d_->worksheets_.push_back(detail::worksheet_impl(this, title)); - create_relationship("rId" + string::from(d_->relationships_.size() + 1), + create_relationship("rId" + std::to_string(d_->relationships_.size() + 1), sheet_filename, relationship::type::worksheet); @@ -217,7 +217,7 @@ int workbook::get_index(xlnt::worksheet worksheet) throw std::runtime_error("worksheet isn't owned by this workbook"); } -void workbook::create_named_range(const string &name, worksheet range_owner, const range_reference &reference) +void workbook::create_named_range(const std::string &name, worksheet range_owner, const range_reference &reference) { auto match = get_sheet_by_name(range_owner.get_title()); if (match != nullptr) @@ -228,7 +228,7 @@ void workbook::create_named_range(const string &name, worksheet range_owner, con throw std::runtime_error("worksheet isn't owned by this workbook"); } -void workbook::remove_named_range(const string &name) +void workbook::remove_named_range(const std::string &name) { for (auto ws : *this) { @@ -242,7 +242,7 @@ void workbook::remove_named_range(const string &name) throw std::runtime_error("named range not found"); } -range workbook::get_named_range(const string &name) +range workbook::get_named_range(const std::string &name) { for (auto ws : *this) { @@ -271,7 +271,7 @@ bool workbook::load(const std::vector &data) return true; } -bool workbook::load(const string &filename) +bool workbook::load(const std::string &filename) { excel_serializer serializer_(*this); serializer_.load_workbook(filename); @@ -289,12 +289,12 @@ bool workbook::get_guess_types() const return d_->guess_types_; } -void workbook::create_relationship(const string &id, const string &target, relationship::type type) +void workbook::create_relationship(const std::string &id, const std::string &target, relationship::type type) { d_->relationships_.push_back(relationship(type, id, target)); } -relationship workbook::get_relationship(const string &id) const +relationship workbook::get_relationship(const std::string &id) const { for (auto &rel : d_->relationships_) { @@ -317,7 +317,7 @@ void workbook::remove_sheet(worksheet ws) throw std::runtime_error("worksheet not owned by this workbook"); } - auto sheet_filename = "worksheets/sheet" + string::from(d_->worksheets_.size()) + ".xml"; + auto sheet_filename = "worksheets/sheet" + std::to_string(d_->worksheets_.size()) + ".xml"; auto rel_iter = std::find_if(d_->relationships_.begin(), d_->relationships_.end(), [=](relationship &r) { return r.get_target_uri() == sheet_filename; }); @@ -344,22 +344,22 @@ worksheet workbook::create_sheet(std::size_t index) } // TODO: There should be a better way to do this... -std::size_t workbook::index_from_ws_filename(const string &ws_filename) +std::size_t workbook::index_from_ws_filename(const std::string &ws_filename) { - string sheet_index_string(ws_filename); + std::string sheet_index_string(ws_filename); sheet_index_string = sheet_index_string.substr(0, sheet_index_string.find('.')); sheet_index_string = sheet_index_string.substr(sheet_index_string.find_last_of('/')); auto iter = sheet_index_string.end(); - --iter; - while (isdigit((*iter))) - --iter; + iter--; + while (isdigit(*iter)) + iter--; auto first_digit = static_cast(iter - sheet_index_string.begin()); sheet_index_string = sheet_index_string.substr(first_digit + 1); - auto sheet_index = sheet_index_string.to() - 1; + auto sheet_index = static_cast(std::stoll(sheet_index_string) - 1); return sheet_index; } -worksheet workbook::create_sheet(const string &title, const relationship &rel) +worksheet workbook::create_sheet(const std::string &title, const relationship &rel) { d_->worksheets_.push_back(detail::worksheet_impl(this, title)); @@ -373,7 +373,7 @@ worksheet workbook::create_sheet(const string &title, const relationship &rel) return worksheet(&d_->worksheets_[index]); } -worksheet workbook::create_sheet(std::size_t index, const string &title) +worksheet workbook::create_sheet(std::size_t index, const std::string &title) { auto ws = create_sheet(index); ws.set_title(title); @@ -381,21 +381,21 @@ worksheet workbook::create_sheet(std::size_t index, const string &title) return ws; } -worksheet workbook::create_sheet(const string &title) +worksheet workbook::create_sheet(const std::string &title) { if (title.length() > 31) { throw sheet_title_exception(title); } - if (std::find_if(title.data(), title.data() + title.num_bytes(), [](char c) { + if (std::find_if(title.begin(), title.end(), [](char c) { return c == '*' || c == ':' || c == '/' || c == '\\' || c == '?' || c == '[' || c == ']'; - }) != title.data() + title.num_bytes()) + }) != title.end()) { throw sheet_title_exception(title); } - string unique_title = title; + std::string unique_title = title; if (std::find_if(d_->worksheets_.begin(), d_->worksheets_.end(), [&](detail::worksheet_impl &ws) { return worksheet(&ws).get_title() == unique_title; @@ -407,7 +407,7 @@ worksheet workbook::create_sheet(const string &title) return worksheet(&ws).get_title() == unique_title; }) != d_->worksheets_.end()) { - unique_title = title + string::from(suffix); + unique_title = title + std::to_string(suffix); suffix++; } } @@ -438,9 +438,9 @@ workbook::const_iterator workbook::cend() const return const_iterator(*this, d_->worksheets_.size()); } -std::vector workbook::get_sheet_names() const +std::vector workbook::get_sheet_names() const { - std::vector names; + std::vector names; for (auto ws : *this) { @@ -450,7 +450,7 @@ std::vector workbook::get_sheet_names() const return names; } -worksheet workbook::operator[](const string &name) +worksheet workbook::operator[](const std::string &name) { return get_sheet_by_name(name); } @@ -477,7 +477,7 @@ bool workbook::save(std::vector &data) return true; } -bool workbook::save(const string &filename) +bool workbook::save(const std::string &filename) { excel_serializer serializer(*this); serializer.save_workbook(filename); @@ -589,7 +589,7 @@ void workbook::add_number_format(const number_format &number_format_) } } -void workbook::set_code_name(const string & /*code_name*/) +void workbook::set_code_name(const std::string & /*code_name*/) { } @@ -903,17 +903,17 @@ const std::vector &workbook::get_root_relationships() const return d_->root_relationships_; } -std::vector &workbook::get_shared_strings() +std::vector &workbook::get_shared_strings() { return d_->shared_strings_; } -const std::vector &workbook::get_shared_strings() const +const std::vector &workbook::get_shared_strings() const { return d_->shared_strings_; } -void workbook::add_shared_string(const string &shared) +void workbook::add_shared_string(const std::string &shared) { //TODO: inefficient, use a set or something? for(auto &s : d_->shared_strings_) @@ -924,9 +924,4 @@ void workbook::add_shared_string(const string &shared) d_->shared_strings_.push_back(shared); } -void workbook::create_named_range(const string &name, worksheet owner, const string &reference_string) -{ - create_named_range(name, owner, range_reference(reference_string)); -} - } // namespace xlnt diff --git a/source/worksheet/range.cpp b/source/worksheet/range.cpp index bbb46b6f..f4570a1d 100644 --- a/source/worksheet/range.cpp +++ b/source/worksheet/range.cpp @@ -146,9 +146,10 @@ cell_vector range::get_vector(std::size_t vector_index) return cell_vector(ws_, reference, order_); } - range_reference reference(column_t(static_cast(ref_.get_top_left().get_column().index + vector_index)), + range_reference reference( + static_cast(static_cast(ref_.get_top_left().get_column().index) + vector_index), ref_.get_top_left().get_row(), - column_t(static_cast(ref_.get_top_left().get_column().index + vector_index)), + static_cast(static_cast(ref_.get_top_left().get_column().index) + vector_index), ref_.get_bottom_right().get_row()); return cell_vector(ws_, reference, order_); diff --git a/source/worksheet/range_reference.cpp b/source/worksheet/range_reference.cpp index 0e61d7a7..007bdfbb 100644 --- a/source/worksheet/range_reference.cpp +++ b/source/worksheet/range_reference.cpp @@ -16,15 +16,15 @@ range_reference::range_reference() : range_reference("A1") { } -range_reference::range_reference(const char *range_string) : range_reference(string(range_string)) +range_reference::range_reference(const char *range_string) : range_reference(std::string(range_string)) { } -range_reference::range_reference(const string &range_string) : top_left_("A1"), bottom_right_("A1") +range_reference::range_reference(const std::string &range_string) : top_left_("A1"), bottom_right_("A1") { auto colon_index = range_string.find(':'); - if (colon_index != string::npos) + if (colon_index != std::string::npos) { top_left_ = cell_reference(range_string.substr(0, colon_index)); bottom_right_ = cell_reference(range_string.substr(colon_index + 1)); @@ -68,7 +68,7 @@ bool range_reference::is_single_cell() const return get_width() == 0 && get_height() == 0; } -string range_reference::to_string() const +std::string range_reference::to_string() const { return top_left_.to_string() + ":" + bottom_right_.to_string(); } diff --git a/source/worksheet/sheet_protection.cpp b/source/worksheet/sheet_protection.cpp index 4fabf1c9..ed629683 100644 --- a/source/worksheet/sheet_protection.cpp +++ b/source/worksheet/sheet_protection.cpp @@ -6,26 +6,26 @@ namespace xlnt { -void sheet_protection::set_password(const string &password) +void sheet_protection::set_password(const std::string &password) { hashed_password_ = hash_password(password); } template -string int_to_hex(T i) +std::string int_to_hex(T i) { std::stringstream stream; stream << std::hex << i; - return stream.str().c_str(); + return stream.str(); } -string sheet_protection::hash_password(const string &plaintext_password) +std::string sheet_protection::hash_password(const std::string &plaintext_password) { int password = 0x0000; + int i = 1; - for (int i = 1; i <= plaintext_password.num_bytes(); i++) + for (auto character : plaintext_password) { - char character = plaintext_password.data()[i - 1]; int value = character << i; int rotated_bits = value >> 15; value &= 0x7fff; @@ -33,17 +33,12 @@ string sheet_protection::hash_password(const string &plaintext_password) i++; } - password ^= plaintext_password.num_bytes(); + password ^= plaintext_password.size(); password ^= 0xCE4B; - string hashed = int_to_hex(password); - auto iter = hashed.data(); - - while (iter != hashed.data() + hashed.num_bytes()) - { - *iter = std::toupper(*iter, std::locale::classic()); - } - + std::string hashed = int_to_hex(password); + std::transform(hashed.begin(), hashed.end(), hashed.begin(), + [](char c) { return std::toupper(c, std::locale::classic()); }); return hashed; } } diff --git a/source/worksheet/tests/test_worksheet.hpp b/source/worksheet/tests/test_worksheet.hpp index 6a65d64d..3e809da5 100644 --- a/source/worksheet/tests/test_worksheet.hpp +++ b/source/worksheet/tests/test_worksheet.hpp @@ -35,7 +35,7 @@ public: { xlnt::worksheet ws(wb_); - const std::vector> expected = + const std::vector> expected = { { "A1", "B1", "C1" }, { "A2", "B2", "C2" }, @@ -64,7 +64,7 @@ public: { std::size_t row = 0; std::size_t column = 0; - xlnt::string coordinate = "A1"; + std::string coordinate = "A1"; xlnt::worksheet ws(wb_); @@ -85,7 +85,7 @@ public: { xlnt::worksheet ws(wb_); - const std::vector> expected = + const std::vector> expected = { { "A1", "B1", "C1" }, { "A2", "B2", "C2" }, @@ -115,7 +115,7 @@ public: xlnt::worksheet ws(wb_); auto rows = ws.rows("A1:C4", 1, 3); - const std::vector> expected = + const std::vector> expected = { { "D2", "E2", "F2" }, { "D3", "E3", "F3" }, @@ -222,9 +222,9 @@ public: { xlnt::worksheet ws(wb_); ws.get_cell("A1").set_hyperlink("http://test.com"); - TS_ASSERT_EQUALS("http://test.com", ws.get_cell("A1").get_value()); + TS_ASSERT_EQUALS("http://test.com", ws.get_cell("A1").get_value()); ws.get_cell("A1").set_value("test"); - TS_ASSERT_EQUALS("test", ws.get_cell("A1").get_value()); + TS_ASSERT_EQUALS("test", ws.get_cell("A1").get_value()); TS_ASSERT_EQUALS(ws.get_cell("A1").get_hyperlink().get_target_uri(), "http://test.com"); } @@ -243,25 +243,25 @@ public: void test_append() { xlnt::worksheet ws(wb_); - ws.append(std::vector {"value"}); - TS_ASSERT_EQUALS("value", ws.get_cell("A1").get_value()); + ws.append(std::vector {"value"}); + TS_ASSERT_EQUALS("value", ws.get_cell("A1").get_value()); } void test_append_list() { xlnt::worksheet ws(wb_); - ws.append(std::vector {"This is A1", "This is B1"}); + ws.append(std::vector {"This is A1", "This is B1"}); - TS_ASSERT_EQUALS("This is A1", ws.get_cell("A1").get_value()); - TS_ASSERT_EQUALS("This is B1", ws.get_cell("B1").get_value()); + TS_ASSERT_EQUALS("This is A1", ws.get_cell("A1").get_value()); + TS_ASSERT_EQUALS("This is B1", ws.get_cell("B1").get_value()); } void test_append_dict_letter() { xlnt::worksheet ws(wb_); - const std::unordered_map dict_letter = + const std::unordered_map dict_letter = { { "A", "This is A1" }, { "C", "This is C1" } @@ -269,15 +269,15 @@ public: ws.append(dict_letter); - TS_ASSERT_EQUALS("This is A1", ws.get_cell("A1").get_value()); - TS_ASSERT_EQUALS("This is C1", ws.get_cell("C1").get_value()); + TS_ASSERT_EQUALS("This is A1", ws.get_cell("A1").get_value()); + TS_ASSERT_EQUALS("This is C1", ws.get_cell("C1").get_value()); } void test_append_dict_index() { xlnt::worksheet ws(wb_); - const std::unordered_map dict_index = + const std::unordered_map dict_index = { { 1, "This is A1" }, { 3, "This is C1" } @@ -285,8 +285,8 @@ public: ws.append(dict_index); - TS_ASSERT_EQUALS("This is A1", ws.get_cell("A1").get_value()); - TS_ASSERT_EQUALS("This is C1", ws.get_cell("C1").get_value()); + TS_ASSERT_EQUALS("This is A1", ws.get_cell("A1").get_value()); + TS_ASSERT_EQUALS("This is C1", ws.get_cell("C1").get_value()); } void _test_bad_append() @@ -317,15 +317,15 @@ public: { xlnt::worksheet ws(wb_); - ws.append(std::vector {"This is A1", "This is B1"}); - ws.append(std::vector {"This is A2", "This is B2"}); + ws.append(std::vector {"This is A1", "This is B1"}); + ws.append(std::vector {"This is A2", "This is B2"}); auto vals = ws.get_range("A1:B2"); - TS_ASSERT_EQUALS(vals[0][0].get_value(), "This is A1"); - TS_ASSERT_EQUALS(vals[0][1].get_value(), "This is B1"); - TS_ASSERT_EQUALS(vals[1][0].get_value(), "This is A2"); - TS_ASSERT_EQUALS(vals[1][1].get_value(), "This is B2"); + TS_ASSERT_EQUALS(vals[0][0].get_value(), "This is A1"); + TS_ASSERT_EQUALS(vals[0][1].get_value(), "This is B1"); + TS_ASSERT_EQUALS(vals[1][0].get_value(), "This is A2"); + TS_ASSERT_EQUALS(vals[1][1].get_value(), "This is B2"); } void _test_append_cell() @@ -358,9 +358,9 @@ public: auto first_row = rows[0]; auto last_row = rows[8]; - TS_ASSERT_EQUALS(first_row[0].get_value(), "first"); + TS_ASSERT_EQUALS(first_row[0].get_value(), "first"); TS_ASSERT_EQUALS(first_row[0].get_reference(), "A1"); - TS_ASSERT_EQUALS(last_row[2].get_value(), "last"); + TS_ASSERT_EQUALS(last_row[2].get_value(), "last"); } void test_no_cols() @@ -382,8 +382,8 @@ public: TS_ASSERT_EQUALS(cols.length(), 3); - TS_ASSERT_EQUALS(cols[0][0].get_value(), "first"); - TS_ASSERT_EQUALS(cols[2][8].get_value(), "last"); + TS_ASSERT_EQUALS(cols[0][0].get_value(), "first"); + TS_ASSERT_EQUALS(cols[2][8].get_value(), "last"); } void test_auto_filter() @@ -578,7 +578,7 @@ public: void test_set_bad_title() { - xlnt::string title(std::string(50, 'X').c_str()); + std::string title(50, 'X'); TS_ASSERT_THROWS(wb_.create_sheet(title), xlnt::sheet_title_exception); } @@ -884,7 +884,7 @@ public: ws.get_header_footer().get_right_footer().set_font_size(14); ws.get_header_footer().get_right_footer().set_font_color("AABBCC"); - xlnt::string expected_xml_string = + std::string expected_xml_string = "" " " " " diff --git a/source/worksheet/worksheet.cpp b/source/worksheet/worksheet.cpp index 770709ca..0ef082c2 100644 --- a/source/worksheet/worksheet.cpp +++ b/source/worksheet/worksheet.cpp @@ -31,7 +31,7 @@ worksheet::worksheet(const worksheet &rhs) : d_(rhs.d_) { } -worksheet::worksheet(workbook &parent, const string &title) +worksheet::worksheet(workbook &parent, const std::string &title) : d_(title == "" ? parent.create_sheet().d_ : parent.create_sheet(title).d_) { } @@ -41,7 +41,7 @@ bool worksheet::has_frozen_panes() const return get_frozen_panes() != cell_reference("A1"); } -string worksheet::unique_sheet_name(const string &value) const +std::string worksheet::unique_sheet_name(const std::string &value) const { auto names = get_parent().get_sheet_names(); auto match = std::find(names.begin(), names.end(), value); @@ -49,12 +49,12 @@ string worksheet::unique_sheet_name(const string &value) const while (match != names.end()) { append++; - match = std::find(names.begin(), names.end(), value + string::from(append)); + match = std::find(names.begin(), names.end(), value + std::to_string(append)); } - return append == 0 ? value : value + string::from(append); + return append == 0 ? value : value + std::to_string(append); } -void worksheet::create_named_range(const string &name, const range_reference &reference) +void worksheet::create_named_range(const std::string &name, const range_reference &reference) { std::vector targets; targets.push_back({ *this, reference }); @@ -63,7 +63,7 @@ void worksheet::create_named_range(const string &name, const range_reference &re range worksheet::operator()(const xlnt::cell_reference &top_left, const xlnt::cell_reference &bottom_right) { - return get_range(range_reference(top_left, bottom_right)); + return get_range({ top_left, bottom_right }); } cell worksheet::operator[](const cell_reference &ref) @@ -91,26 +91,6 @@ void worksheet::auto_filter(const range_reference &reference) d_->auto_filter_ = reference; } -void worksheet::auto_filter(const string &reference_string) -{ - auto_filter(range_reference(reference_string)); -} - -void worksheet::merge_cells(const string &reference_string) -{ - merge_cells(range_reference(reference_string)); -} - -void worksheet::unmerge_cells(const string &reference_string) -{ - unmerge_cells(range_reference(reference_string)); -} - -range worksheet::get_range(const string &reference_string) -{ - return get_range(range_reference(reference_string)); -} - void worksheet::auto_filter(const xlnt::range &range) { auto_filter(range.get_reference()); @@ -141,7 +121,7 @@ const page_setup &worksheet::get_page_setup() const return d_->page_setup_; } -string worksheet::to_string() const +std::string worksheet::to_string() const { return "title_ + "\">"; } @@ -195,7 +175,7 @@ std::list worksheet::get_cell_collection() return cells; } -string worksheet::get_title() const +std::string worksheet::get_title() const { if (d_ == nullptr) { @@ -204,7 +184,7 @@ string worksheet::get_title() const return d_->title_; } -void worksheet::set_title(const string &title) +void worksheet::set_title(const std::string &title) { d_->title_ = title; } @@ -219,7 +199,7 @@ void worksheet::freeze_panes(xlnt::cell top_left_cell) d_->freeze_panes_ = top_left_cell.get_reference(); } -void worksheet::freeze_panes(const string &top_left_coordinate) +void worksheet::freeze_panes(const std::string &top_left_coordinate) { d_->freeze_panes_ = cell_reference(top_left_coordinate); } @@ -256,7 +236,7 @@ bool worksheet::has_row_properties(row_t row) const return d_->row_properties_.find(row) != d_->row_properties_.end(); } -range worksheet::get_named_range(const string &name) +range worksheet::get_named_range(const std::string &name) { if (!has_named_range(name)) { @@ -368,9 +348,9 @@ const std::vector &worksheet::get_relationships() const return d_->relationships_; } -relationship worksheet::create_relationship(relationship::type type, const string &target_uri) +relationship worksheet::create_relationship(relationship::type type, const std::string &target_uri) { - string r_id = "rId" + string::from(d_->relationships_.size() + 1); + std::string r_id = "rId" + std::to_string(d_->relationships_.size() + 1); d_->relationships_.push_back(relationship(type, r_id, target_uri)); return d_->relationships_.back(); } @@ -438,7 +418,7 @@ void worksheet::append() get_cell(cell_reference(1, get_next_row())); } -void worksheet::append(const std::vector &cells) +void worksheet::append(const std::vector &cells) { xlnt::cell_reference next(1, get_next_row()); @@ -494,7 +474,7 @@ void worksheet::append(const std::vector &cells) } } -void worksheet::append(const std::unordered_map &cells) +void worksheet::append(const std::unordered_map &cells) { auto row = get_next_row(); @@ -504,7 +484,7 @@ void worksheet::append(const std::unordered_map &cells) } } -void worksheet::append(const std::unordered_map &cells) +void worksheet::append(const std::unordered_map &cells) { auto row = get_next_row(); @@ -530,12 +510,12 @@ xlnt::range worksheet::rows() const return get_range(calculate_dimension()); } -xlnt::range worksheet::rows(const string &range_string) const +xlnt::range worksheet::rows(const std::string &range_string) const { return get_range(range_reference(range_string)); } -xlnt::range worksheet::rows(const string &range_string, int row_offset, int column_offset) const +xlnt::range worksheet::rows(const std::string &range_string, int row_offset, int column_offset) const { range_reference reference(range_string); return get_range(reference.make_offset(column_offset, row_offset)); @@ -581,7 +561,7 @@ range worksheet::operator[](const range_reference &ref) return get_range(ref); } -range worksheet::operator[](const string &name) +range worksheet::operator[](const std::string &name) { if (has_named_range(name)) { @@ -590,12 +570,12 @@ range worksheet::operator[](const string &name) return get_range(range_reference(name)); } -bool worksheet::has_named_range(const string &name) +bool worksheet::has_named_range(const std::string &name) { return d_->named_ranges_.find(name) != d_->named_ranges_.end(); } -void worksheet::remove_named_range(const string &name) +void worksheet::remove_named_range(const std::string &name) { if (!has_named_range(name)) { @@ -652,7 +632,7 @@ void worksheet::set_parent(xlnt::workbook &wb) d_->parent_ = &wb; } -std::vector worksheet::get_formula_attributes() const +std::vector worksheet::get_formula_attributes() const { return {}; }