mirror of
https://github.com/tfussell/xlnt.git
synced 2024-03-22 13:11:17 +08:00
revert to 3bb988c422
reluctantly
This commit is contained in:
parent
5bae849521
commit
40fc54f55e
|
@ -24,12 +24,12 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
#include <xlnt/cell/types.hpp>
|
||||
#include <xlnt/utils/string.hpp>
|
||||
|
||||
#include <xlnt/xlnt_config.hpp>
|
||||
#include "xlnt_config.hpp"
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
|
@ -87,7 +87,7 @@ public:
|
|||
/// <summary>
|
||||
/// Return a map of error strings such as \#DIV/0! and their associated indices.
|
||||
/// </summary>
|
||||
static const std::unordered_map<string, int> &error_codes();
|
||||
static const std::unordered_map<std::string, int> &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:
|
|||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
template <typename T>
|
||||
T get_value() const;
|
||||
|
@ -135,8 +135,7 @@ public:
|
|||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
/// as for std::string and xlnt datetime types: date, time, datetime, and timedelta.
|
||||
template <typename T>
|
||||
void set_value(T value);
|
||||
|
||||
|
@ -195,7 +194,7 @@ public:
|
|||
/// <summary>
|
||||
/// Add a hyperlink to this cell pointing to the URI of the given value.
|
||||
/// </summary>
|
||||
void set_hyperlink(const string &value);
|
||||
void set_hyperlink(const std::string &value);
|
||||
|
||||
/// <summary>
|
||||
/// 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:
|
|||
/// <summary>
|
||||
/// Returns a string describing this cell like <Cell Sheet.A1>.
|
||||
/// </summary>
|
||||
string to_repr() const;
|
||||
std::string to_repr() const;
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
string to_string() const;
|
||||
std::string to_string() const;
|
||||
|
||||
// merging
|
||||
|
||||
|
@ -329,12 +328,12 @@ public:
|
|||
/// <summary>
|
||||
/// Return the error string that is stored in this cell.
|
||||
/// </summary>
|
||||
string get_error() const;
|
||||
std::string get_error() const;
|
||||
|
||||
/// <summary>
|
||||
/// Directly assign the value of this cell to be the given error.
|
||||
/// </summary>
|
||||
void set_error(const string &error);
|
||||
void set_error(const std::string &error);
|
||||
|
||||
/// <summary>
|
||||
/// Return a cell from this cell's parent workbook at
|
||||
|
@ -381,19 +380,13 @@ public:
|
|||
/// <summary>
|
||||
/// Return true if this cell is uninitialized.
|
||||
/// </summary>
|
||||
friend XLNT_FUNCTION bool operator==(std::nullptr_t, const cell &cell);
|
||||
friend bool operator==(std::nullptr_t, const cell &cell);
|
||||
|
||||
/// <summary>
|
||||
/// Return the result of left.get_reference() < right.get_reference().
|
||||
/// What's the point of this?
|
||||
/// </summary>
|
||||
friend XLNT_FUNCTION bool operator<(const cell left, const cell right);
|
||||
|
||||
/// <summary>
|
||||
/// Convenience function for writing cell to an ostream.
|
||||
/// Uses cell::to_string() internally.
|
||||
/// </summary>
|
||||
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_;
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Convenience function for writing cell to an ostream.
|
||||
/// Uses cell::to_string() internally.
|
||||
/// </summary>
|
||||
inline std::ostream & XLNT_FUNCTION operator<<(std::ostream &stream, const xlnt::cell &cell)
|
||||
{
|
||||
return stream << cell.to_string();
|
||||
}
|
||||
|
||||
} // namespace xlnt
|
||||
|
|
|
@ -23,12 +23,12 @@
|
|||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include <xlnt/cell/types.hpp>
|
||||
#include <xlnt/utils/string.hpp>
|
||||
|
||||
#include <xlnt/xlnt_config.hpp>
|
||||
#include "xlnt_config.hpp"
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
|
@ -57,7 +57,7 @@ class XLNT_CLASS cell_reference
|
|||
/// <summary>
|
||||
/// Split a coordinate string like "A1" into an equivalent pair like {"A", 1}.
|
||||
/// </summary>
|
||||
static std::pair<string, row_t> split_reference(const string &reference_string);
|
||||
static std::pair<std::string, row_t> split_reference(const std::string &reference_string);
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
static std::pair<string, row_t> split_reference(const string &reference_string, bool &absolute_column,
|
||||
static std::pair<std::string, row_t> split_reference(const std::string &reference_string, bool &absolute_column,
|
||||
bool &absolute_row);
|
||||
|
||||
// constructors
|
||||
|
@ -85,13 +85,13 @@ class XLNT_CLASS cell_reference
|
|||
/// <summary>
|
||||
/// Constructs a cell_reference from a string reprenting a cell coordinate (e.g. $B14).
|
||||
/// </summary>
|
||||
cell_reference(const string &reference_string);
|
||||
cell_reference(const std::string &reference_string);
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a cell_reference from a string reprenting a column (e.g. A) and
|
||||
/// a 1-indexed row.
|
||||
/// </summary>
|
||||
cell_reference(const string &column, row_t row);
|
||||
cell_reference(const std::string &column, row_t row);
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a cell_reference from a 1-indexed column index and row index.
|
||||
|
@ -163,7 +163,7 @@ class XLNT_CLASS cell_reference
|
|||
/// <summary>
|
||||
/// Set the column of this reference from a string that identifies a particular column.
|
||||
/// </summary>
|
||||
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
|
|||
/// <summary>
|
||||
/// Return a string like "A1" for cell_reference(1, 1).
|
||||
/// </summary>
|
||||
string to_string() const;
|
||||
std::string to_string() const;
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
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
|
|||
/// </summary>
|
||||
bool operator==(const char *reference_string) const
|
||||
{
|
||||
return *this == string(reference_string);
|
||||
return *this == std::string(reference_string);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -264,7 +264,7 @@ class XLNT_CLASS cell_reference
|
|||
/// Construct a cell_reference from reference_string and return the result
|
||||
/// of their comparison.
|
||||
/// </summary>
|
||||
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
|
|||
/// </summary>
|
||||
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
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#pragma once
|
||||
|
||||
#include <xlnt/utils/string.hpp>
|
||||
#include <string>
|
||||
|
||||
#include <xlnt/xlnt_config.hpp>
|
||||
#include "xlnt_config.hpp"
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
|
@ -23,19 +23,19 @@ class XLNT_CLASS comment
|
|||
/// <summary>
|
||||
/// 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();
|
||||
|
||||
/// <summary>
|
||||
/// Return the text that will be displayed for this comment.
|
||||
/// </summary>
|
||||
string get_text() const;
|
||||
std::string get_text() const;
|
||||
|
||||
/// <summary>
|
||||
/// Return the author of this comment.
|
||||
/// </summary>
|
||||
string get_author() const;
|
||||
std::string get_author() const;
|
||||
|
||||
/// <summary>
|
||||
/// True if the comments point to the same sell (false if
|
||||
|
|
|
@ -24,10 +24,9 @@
|
|||
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
#include <xlnt/utils/string.hpp>
|
||||
|
||||
#include <xlnt/xlnt_config.hpp>
|
||||
#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.
|
||||
/// </remarks>
|
||||
static index_t column_index_from_string(const string &column_string);
|
||||
static index_t column_index_from_string(const std::string &column_string);
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </remarks>
|
||||
static string column_string_from_index(index_t column_index);
|
||||
static std::string column_string_from_index(index_t column_index);
|
||||
|
||||
/// <summary>
|
||||
/// Default column_t is the first (left-most) column.
|
||||
|
@ -82,12 +81,12 @@ public:
|
|||
/// <summary>
|
||||
/// Construct a column from a string.
|
||||
/// </summary>
|
||||
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)) {}
|
||||
|
||||
/// <summary>
|
||||
/// Construct a column from a string.
|
||||
/// </summary>
|
||||
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)) {}
|
||||
|
||||
/// <summary>
|
||||
/// Copy constructor
|
||||
|
@ -102,7 +101,7 @@ public:
|
|||
/// <summary>
|
||||
/// Return a string representation of this column index.
|
||||
/// </summary>
|
||||
string column_string() const { return column_string_from_index(index); }
|
||||
std::string column_string() const { return column_string_from_index(index); }
|
||||
|
||||
/// <summary>
|
||||
/// Set this column to be the same as rhs's and return reference to self.
|
||||
|
@ -112,7 +111,7 @@ public:
|
|||
/// <summary>
|
||||
/// Set this column to be equal to rhs and return reference to self.
|
||||
/// </summary>
|
||||
column_t &operator=(const string &rhs) { return *this = column_t(rhs); }
|
||||
column_t &operator=(const std::string &rhs) { return *this = column_t(rhs); }
|
||||
|
||||
/// <summary>
|
||||
/// Set this column to be equal to rhs and return reference to self.
|
||||
|
@ -142,7 +141,7 @@ public:
|
|||
/// <summary>
|
||||
/// Return true if this column refers to the same column as other.
|
||||
/// </summary>
|
||||
bool operator==(const string &other) const { return *this == column_t(other); }
|
||||
bool operator==(const std::string &other) const { return *this == column_t(other); }
|
||||
|
||||
/// <summary>
|
||||
/// Return true if this column refers to the same column as other.
|
||||
|
@ -162,7 +161,7 @@ public:
|
|||
/// <summary>
|
||||
/// Return true if this column doesn't refer to the same column as other.
|
||||
/// </summary>
|
||||
bool operator!=(const string &other) const { return !(*this == other); }
|
||||
bool operator!=(const std::string &other) const { return !(*this == other); }
|
||||
|
||||
/// <summary>
|
||||
/// Return true if this column doesn't refer to the same column as other.
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
// @author: see AUTHORS file
|
||||
#pragma once
|
||||
|
||||
#include <xlnt/xlnt_config.hpp>
|
||||
#include "xlnt_config.hpp"
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <xlnt/xlnt_config.hpp>
|
||||
#include "xlnt_config.hpp"
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <xlnt/xlnt_config.hpp>
|
||||
#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<string> get_tokens();
|
||||
std::vector<std::string> 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<string, string> strip_ws_name(const string &range_str);
|
||||
std::pair<std::string, std::string> 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_;
|
||||
};
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
|
||||
#include <xlnt/utils/datetime.hpp>
|
||||
|
||||
#include <xlnt/xlnt_config.hpp>
|
||||
#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;
|
||||
};
|
||||
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <xlnt/utils/string.hpp>
|
||||
|
||||
#include <xlnt/xlnt_config.hpp>
|
||||
#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<default_type> &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_type> default_types_;
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
// @author: see AUTHORS file
|
||||
#pragma once
|
||||
|
||||
#include <xlnt/utils/string.hpp>
|
||||
#include <string>
|
||||
|
||||
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.
|
||||
/// </summary>
|
||||
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 = "");
|
||||
|
||||
/// <summary>
|
||||
/// gets a string that identifies the relationship.
|
||||
/// </summary>
|
||||
string get_id() const
|
||||
std::string get_id() const
|
||||
{
|
||||
return id_;
|
||||
}
|
||||
|
@ -160,7 +158,7 @@ class XLNT_CLASS relationship
|
|||
/// <summary>
|
||||
/// gets the URI of the package or part that owns the relationship.
|
||||
/// </summary>
|
||||
string get_source_uri() const
|
||||
std::string get_source_uri() const
|
||||
{
|
||||
return source_uri_;
|
||||
}
|
||||
|
@ -168,7 +166,7 @@ class XLNT_CLASS relationship
|
|||
/// <summary>
|
||||
/// gets a value that indicates whether the target of the relationship is or External to the Package.
|
||||
/// </summary>
|
||||
target_mode get_target_mode() const
|
||||
target_mode get_target_mode() const
|
||||
{
|
||||
return target_mode_;
|
||||
}
|
||||
|
@ -176,35 +174,31 @@ class XLNT_CLASS relationship
|
|||
/// <summary>
|
||||
/// gets the URI of the target resource of the relationship.
|
||||
/// </summary>
|
||||
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_;
|
||||
};
|
||||
|
||||
|
|
|
@ -4,11 +4,10 @@
|
|||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <xlnt/utils/string.hpp>
|
||||
|
||||
#include <xlnt/xlnt_config.hpp>
|
||||
#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<unsigned char> &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<unsigned char> &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<zip_info> infolist();
|
||||
std::vector<string> namelist();
|
||||
std::vector<std::string> 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<string> &members);
|
||||
void extractall(const string &path, const std::vector<zip_info> &members);
|
||||
void extractall(const std::string &path);
|
||||
void extractall(const std::string &path, const std::vector<std::string> &members);
|
||||
void extractall(const std::string &path, const std::vector<zip_info> &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<bool, string> testzip();
|
||||
std::pair<bool, std::string> 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<mz_zip_archive_tag> archive_;
|
||||
std::vector<char> buffer_;
|
||||
std::stringstream open_stream_;
|
||||
string filename_;
|
||||
std::string filename_;
|
||||
};
|
||||
|
||||
} // namespace xlnt
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
#include <xlnt/cell/comment.hpp>
|
||||
#include <xlnt/worksheet/worksheet.hpp>
|
||||
|
||||
#include <xlnt/xlnt_config.hpp>
|
||||
#include "xlnt_config.hpp"
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <xlnt/xlnt_config.hpp>
|
||||
#include "xlnt_config.hpp"
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
|
||||
#include <xlnt/packaging/zip_file.hpp>
|
||||
|
||||
#include <xlnt/xlnt_config.hpp>
|
||||
#include "xlnt_config.hpp"
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
|
@ -46,12 +46,12 @@ class XLNT_CLASS excel_serializer
|
|||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
static const string central_directory_signature();
|
||||
static const std::string central_directory_signature();
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
static string repair_central_directory(const string &original);
|
||||
static std::string repair_central_directory(const std::string &original);
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
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);
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
bool save_workbook(const string &filename, bool as_template = false);
|
||||
bool save_workbook(const std::string &filename, bool as_template = false);
|
||||
|
||||
/// <summary>
|
||||
/// Create a ZIP file in memory, save workbook to this archive, then assign ZIP file
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
#include <string>
|
||||
|
||||
#include <xlnt/xlnt_config.hpp>
|
||||
#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_;
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <xlnt/utils/string.hpp>
|
||||
|
||||
#include <xlnt/xlnt_config.hpp>
|
||||
#include "xlnt_config.hpp"
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
|
@ -25,12 +24,12 @@ public:
|
|||
/// <summary>
|
||||
/// Return a vector of relationships corresponding to target.
|
||||
/// </summary>
|
||||
std::vector<relationship> read_relationships(const string &target);
|
||||
std::vector<relationship> read_relationships(const std::string &target);
|
||||
|
||||
/// <summary>
|
||||
/// Write relationships to archive for the given target.
|
||||
/// </summary>
|
||||
bool write_relationships(const std::vector<relationship> &relationships, const string &target);
|
||||
bool write_relationships(const std::vector<relationship> &relationships, const std::string &target);
|
||||
|
||||
private:
|
||||
/// <summary>
|
||||
|
|
|
@ -23,11 +23,10 @@
|
|||
// @author: see AUTHORS file
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <xlnt/utils/string.hpp>
|
||||
|
||||
#include <xlnt/xlnt_config.hpp>
|
||||
#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<string> &strings);
|
||||
static xml_document write_shared_strings(const std::vector<string> &strings);
|
||||
static bool read_shared_strings(const xml_document &xml, std::vector<std::string> &strings);
|
||||
static xml_document write_shared_strings(const std::vector<std::string> &strings);
|
||||
};
|
||||
|
||||
} // namespace xlnt
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
|
||||
#include <xlnt/workbook/workbook.hpp>
|
||||
|
||||
#include <xlnt/xlnt_config.hpp>
|
||||
#include "xlnt_config.hpp"
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
|
@ -133,7 +133,7 @@ class XLNT_CLASS style_serializer
|
|||
/// <summary>
|
||||
/// Read and return a pair containing a name and corresponding style from named_style_node.
|
||||
/// </summary>
|
||||
static std::pair<string, style> read_named_style(const xml_node &named_style_node);
|
||||
static std::pair<std::string, style> read_named_style(const xml_node &named_style_node);
|
||||
|
||||
//
|
||||
// Static element writers (i.e. writers that don't use internal state)
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
#include <string>
|
||||
|
||||
#include <xlnt/xlnt_config.hpp>
|
||||
#include "xlnt_config.hpp"
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <xlnt/xlnt_config.hpp>
|
||||
#include "xlnt_config.hpp"
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
|
@ -42,7 +42,7 @@ class xml_node;
|
|||
class XLNT_CLASS workbook_serializer
|
||||
{
|
||||
public:
|
||||
using string_pair = std::pair<string, string>;
|
||||
using string_pair = std::pair<std::string, std::string>;
|
||||
|
||||
workbook_serializer(workbook &wb);
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
|
||||
#include <xlnt/worksheet/worksheet.hpp>
|
||||
|
||||
#include <xlnt/xlnt_config.hpp>
|
||||
#include "xlnt_config.hpp"
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <xlnt/utils/string.hpp>
|
||||
|
||||
#include <xlnt/xlnt_config.hpp>
|
||||
#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<string, string>;
|
||||
using string_pair = std::pair<std::string, std::string>;
|
||||
|
||||
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;
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <xlnt/utils/string.hpp>
|
||||
|
||||
#include <xlnt/xlnt_config.hpp>
|
||||
#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<string, string>;
|
||||
using string_pair = std::pair<std::string, std::string>;
|
||||
|
||||
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<xml_node> 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<string_pair> 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;
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#pragma once
|
||||
|
||||
#include <xlnt/utils/string.hpp>
|
||||
#include <string>
|
||||
|
||||
#include <xlnt/xlnt_config.hpp>
|
||||
#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
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
#include <xlnt/utils/hash_combine.hpp>
|
||||
|
||||
#include <xlnt/xlnt_config.hpp>
|
||||
#include "xlnt_config.hpp"
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
#include <xlnt/utils/hash_combine.hpp>
|
||||
#include <xlnt/styles/side.hpp>
|
||||
|
||||
#include <xlnt/xlnt_config.hpp>
|
||||
#include "xlnt_config.hpp"
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
|
|
|
@ -23,10 +23,11 @@
|
|||
// @author: see AUTHORS file
|
||||
#pragma once
|
||||
|
||||
#include <xlnt/utils/hash_combine.hpp>
|
||||
#include <xlnt/utils/string.hpp>
|
||||
#include <string>
|
||||
|
||||
#include <xlnt/xlnt_config.hpp>
|
||||
#include <xlnt/utils/hash_combine.hpp>
|
||||
|
||||
#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
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
#include <xlnt/styles/color.hpp>
|
||||
#include <xlnt/utils/hash_combine.hpp>
|
||||
|
||||
#include <xlnt/xlnt_config.hpp>
|
||||
#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)
|
||||
{
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
#include <xlnt/utils/hash_combine.hpp>
|
||||
#include <xlnt/styles/color.hpp>
|
||||
|
||||
#include <xlnt/xlnt_config.hpp>
|
||||
#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
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
#include <xlnt/styles/style.hpp>
|
||||
|
||||
#include <xlnt/xlnt_config.hpp>
|
||||
#include "xlnt_config.hpp"
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
|
@ -42,7 +42,7 @@ class XLNT_CLASS named_style
|
|||
}
|
||||
|
||||
private:
|
||||
string name_;
|
||||
std::string name_;
|
||||
style style_;
|
||||
};
|
||||
|
||||
|
|
|
@ -23,12 +23,11 @@
|
|||
// @author: see AUTHORS file
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <utility>
|
||||
|
||||
#include <xlnt/utils/string.hpp>
|
||||
|
||||
#include <xlnt/xlnt_config.hpp>
|
||||
#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
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
|
||||
#include <xlnt/utils/hash_combine.hpp>
|
||||
|
||||
#include <xlnt/xlnt_config.hpp>
|
||||
#include "xlnt_config.hpp"
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
|
||||
#include <xlnt/styles/color.hpp>
|
||||
|
||||
#include <xlnt/xlnt_config.hpp>
|
||||
#include "xlnt_config.hpp"
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
#include <xlnt/styles/number_format.hpp>
|
||||
#include <xlnt/styles/protection.hpp>
|
||||
|
||||
#include <xlnt/xlnt_config.hpp>
|
||||
#include "xlnt_config.hpp"
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
|
|
|
@ -22,9 +22,9 @@
|
|||
// @author: see AUTHORS file
|
||||
#pragma once
|
||||
|
||||
#include <xlnt/utils/string.hpp>
|
||||
#include <string>
|
||||
|
||||
#include <xlnt/xlnt_config.hpp>
|
||||
#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;
|
||||
|
||||
|
|
|
@ -27,34 +27,34 @@
|
|||
|
||||
#include <xlnt/cell/types.hpp>
|
||||
|
||||
#include <xlnt/xlnt_config.hpp>
|
||||
#include "xlnt_config.hpp"
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
/// <summary>
|
||||
/// Error for converting between numeric and A1-style cell references.
|
||||
/// </summary>
|
||||
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);
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// The data submitted which cannot be used directly in Excel files. It
|
||||
/// must be removed or escaped.
|
||||
/// </summary>
|
||||
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);
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Error for bad column names in A1-style cell references.
|
||||
/// </summary>
|
||||
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
|
|||
/// <summary>
|
||||
/// Error for any data type inconsistencies.
|
||||
/// </summary>
|
||||
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
|
|||
/// <summary>
|
||||
/// Error for badly formatted named ranges.
|
||||
/// </summary>
|
||||
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
|
|||
/// <summary>
|
||||
/// Error for bad sheet names.
|
||||
/// </summary>
|
||||
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);
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Error for trying to open a non-ooxml file.
|
||||
/// </summary>
|
||||
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);
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Error for trying to modify a read-only workbook.
|
||||
/// </summary>
|
||||
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
|
|||
/// <summary>
|
||||
/// Error when a references number format is not in the stylesheet.
|
||||
/// </summary>
|
||||
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
|
|||
/// <summary>
|
||||
/// Error when an attribute value is invalid.
|
||||
/// </summary>
|
||||
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("")
|
||||
{
|
||||
}
|
||||
};
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
#include <functional>
|
||||
|
||||
#include <xlnt/xlnt_config.hpp>
|
||||
#include "xlnt_config.hpp"
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
|
|
|
@ -1,317 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#ifdef XLNT_STD_STRING
|
||||
#include <string>
|
||||
#endif
|
||||
|
||||
#include <xlnt/xlnt_config.hpp>
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
template<typename T>
|
||||
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<std::bidirectional_iterator_tag, code_point>
|
||||
{
|
||||
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<std::bidirectional_iterator_tag, code_point>
|
||||
{
|
||||
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<iterator>;
|
||||
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
|
||||
|
||||
static const size_type npos = -1;
|
||||
|
||||
template<typename T>
|
||||
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 <class InputIterator>
|
||||
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<typename T>
|
||||
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<byte> *data_;
|
||||
std::unordered_map<size_type, size_type> *code_point_byte_offsets_;
|
||||
};
|
||||
|
||||
} // namespace xlnt
|
||||
|
||||
namespace std {
|
||||
|
||||
template<>
|
||||
struct hash<xlnt::string>
|
||||
{
|
||||
std::size_t operator()(const xlnt::string &str) const
|
||||
{
|
||||
return str.hash();
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct less<xlnt::string>
|
||||
{
|
||||
std::size_t operator()(const xlnt::string &left, const xlnt::string &right) const
|
||||
{
|
||||
return left < right;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace std
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
#include <string>
|
||||
|
||||
#include <xlnt/xlnt_config.hpp>
|
||||
#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
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <xlnt/xlnt_config.hpp>
|
||||
#include "xlnt_config.hpp"
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
|
|
|
@ -3,14 +3,14 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <xlnt/xlnt_config.hpp>
|
||||
#include "xlnt_config.hpp"
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
class range_reference;
|
||||
class worksheet;
|
||||
|
||||
std::vector<std::pair<string, string>> XLNT_FUNCTION split_named_range(const string &named_range_string);
|
||||
std::vector<std::pair<std::string, std::string>> 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<target> &targets);
|
||||
named_range(const std::string &name, const std::vector<target> &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<target> targets_;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <xlnt/xlnt_config.hpp>
|
||||
#include "xlnt_config.hpp"
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
|
||||
#include <xlnt/packaging/relationship.hpp>
|
||||
|
||||
#include <xlnt/xlnt_config.hpp>
|
||||
#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<string> get_sheet_names() const;
|
||||
std::vector<std::string> get_sheet_names() const;
|
||||
|
||||
document_properties &get_properties();
|
||||
const document_properties &get_properties() const;
|
||||
|
||||
// named ranges
|
||||
std::vector<named_range> 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<unsigned char> &data);
|
||||
bool save(const string &filename);
|
||||
bool save(const std::string &filename);
|
||||
bool load(const std::vector<unsigned char> &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<relationship> &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<relationship> &get_root_relationships() const;
|
||||
|
||||
void add_shared_string(const string &shared);
|
||||
std::vector<string> &get_shared_strings();
|
||||
const std::vector<string> &get_shared_strings() const;
|
||||
void add_shared_string(const std::string &shared);
|
||||
std::vector<std::string> &get_shared_strings();
|
||||
const std::vector<std::string> &get_shared_strings() const;
|
||||
|
||||
private:
|
||||
friend class worksheet;
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#include <xlnt/worksheet/major_order.hpp>
|
||||
#include <xlnt/worksheet/worksheet.hpp>
|
||||
|
||||
#include <xlnt/xlnt_config.hpp>
|
||||
#include "xlnt_config.hpp"
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
|
@ -18,7 +18,7 @@ class XLNT_CLASS cell_vector
|
|||
{
|
||||
public:
|
||||
template <bool is_const = true>
|
||||
class XLNT_CLASS common_iterator : public std::iterator<std::bidirectional_iterator_tag, cell>
|
||||
class common_iterator : public std::iterator<std::bidirectional_iterator_tag, cell>
|
||||
{
|
||||
public:
|
||||
common_iterator(worksheet ws, const cell_reference &start_cell, major_order order = major_order::row)
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
// @author: see AUTHORS file
|
||||
#pragma once
|
||||
|
||||
#include <xlnt/xlnt_config.hpp>
|
||||
#include "xlnt_config.hpp"
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <xlnt/xlnt_config.hpp>
|
||||
#include "xlnt_config.hpp"
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
// @author: see AUTHORS file
|
||||
#pragma once
|
||||
|
||||
#include <xlnt/xlnt_config.hpp>
|
||||
#include "xlnt_config.hpp"
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
// @author: see AUTHORS file
|
||||
#pragma once
|
||||
|
||||
#include <xlnt/xlnt_config.hpp>
|
||||
#include "xlnt_config.hpp"
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
// @author: see AUTHORS file
|
||||
#pragma once
|
||||
|
||||
#include <xlnt/xlnt_config.hpp>
|
||||
#include "xlnt_config.hpp"
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
#include <xlnt/worksheet/range_reference.hpp>
|
||||
#include <xlnt/worksheet/worksheet.hpp>
|
||||
|
||||
#include <xlnt/xlnt_config.hpp>
|
||||
#include "xlnt_config.hpp"
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
|
@ -40,7 +40,7 @@ class XLNT_CLASS range
|
|||
{
|
||||
public:
|
||||
template <bool is_const = true>
|
||||
class XLNT_CLASS common_iterator : public std::iterator<std::bidirectional_iterator_tag, cell>
|
||||
class common_iterator : public std::iterator<std::bidirectional_iterator_tag, cell>
|
||||
{
|
||||
public:
|
||||
common_iterator(worksheet ws, const range_reference &start_cell, major_order order = major_order::row)
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
#include <xlnt/cell/cell_reference.hpp>
|
||||
|
||||
#include <xlnt/xlnt_config.hpp>
|
||||
#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<cell_reference, cell_reference> &reference_pair);
|
||||
range_reference(const std::string &range_string);
|
||||
range_reference(const char *range_string);
|
||||
range_reference(const std::pair<cell_reference, cell_reference> &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;
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
// @author: see AUTHORS file
|
||||
#pragma once
|
||||
|
||||
#include <xlnt/xlnt_config.hpp>
|
||||
#include "xlnt_config.hpp"
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
// @author: see AUTHORS file
|
||||
#pragma once
|
||||
|
||||
#include <xlnt/xlnt_config.hpp>
|
||||
#include "xlnt_config.hpp"
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
|
|
|
@ -1,24 +1,24 @@
|
|||
#pragma once
|
||||
|
||||
#include <xlnt/utils/string.hpp>
|
||||
#include <string>
|
||||
|
||||
#include <xlnt/xlnt_config.hpp>
|
||||
#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
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
// @author: see AUTHORS file
|
||||
#pragma once
|
||||
|
||||
#include <xlnt/xlnt_config.hpp>
|
||||
#include "xlnt_config.hpp"
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
#include <xlnt/packaging/relationship.hpp>
|
||||
#include <xlnt/worksheet/page_setup.hpp>
|
||||
|
||||
#include <xlnt/xlnt_config.hpp>
|
||||
#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_;
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
|
@ -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_;
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
|
@ -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<cell> 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<int, int> &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<relationship> &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<range_reference> get_merged_ranges() const;
|
||||
|
||||
// append
|
||||
void append();
|
||||
void append(const std::vector<string> &cells);
|
||||
void append(const std::vector<std::string> &cells);
|
||||
void append(const std::vector<int> &cells);
|
||||
void append(const std::vector<date> &cells);
|
||||
void append(const std::vector<cell> &cells);
|
||||
void append(const std::unordered_map<string, string> &cells);
|
||||
void append(const std::unordered_map<int, string> &cells);
|
||||
void append(const std::unordered_map<std::string, std::string> &cells);
|
||||
void append(const std::unordered_map<int, std::string> &cells);
|
||||
|
||||
void append(const std::vector<int>::const_iterator begin, const std::vector<int>::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<string> get_formula_attributes() const;
|
||||
std::vector<std::string> get_formula_attributes() const;
|
||||
|
||||
void set_sheet_state(page_setup::sheet_state state);
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
// @author: see AUTHORS file
|
||||
#pragma once
|
||||
|
||||
#include <xlnt/xlnt_config.hpp>
|
||||
#include "xlnt_config.hpp"
|
||||
|
||||
namespace xlnt {
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
#include <string>
|
||||
|
||||
#include <xlnt/xlnt_config.hpp>
|
||||
#include "xlnt_config.hpp"
|
||||
|
||||
#include <xlnt/cell/cell.hpp>
|
||||
#include <xlnt/cell/cell_reference.hpp>
|
||||
|
|
|
@ -54,27 +54,18 @@ enum class limit_style
|
|||
/// </summary>
|
||||
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
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
#include <xlnt/styles/color.hpp>
|
||||
#include <xlnt/utils/datetime.hpp>
|
||||
#include <xlnt/utils/exceptions.hpp>
|
||||
#include <xlnt/utils/string.hpp>
|
||||
#include <xlnt/workbook/workbook.hpp>
|
||||
#include <xlnt/worksheet/column_properties.hpp>
|
||||
#include <xlnt/worksheet/row_properties.hpp>
|
||||
|
@ -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
|
|||
/// <remark>
|
||||
/// This should maybe be in a utility header so it can be used elsewhere.
|
||||
/// </remarks>
|
||||
std::vector<xlnt::string> split_string(const xlnt::string &string, char delim)
|
||||
std::vector<std::string> split_string(const std::string &string, char delim)
|
||||
{
|
||||
std::vector<xlnt::string> split;
|
||||
xlnt::string::size_type previous_index = 0;
|
||||
std::vector<std::string> 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<xlnt::string> split_string(const xlnt::string &string, char delim)
|
|||
return split;
|
||||
}
|
||||
|
||||
std::vector<xlnt::string> split_string_any(const xlnt::string &string, const xlnt::string &delims)
|
||||
std::vector<std::string> split_string_any(const std::string &string, const std::string &delims)
|
||||
{
|
||||
std::vector<xlnt::string> split;
|
||||
xlnt::string::size_type previous_index = 0;
|
||||
std::vector<std::string> 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<xlnt::string> 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<xlnt::string> *colors =
|
||||
new std::vector<xlnt::string>(
|
||||
static const std::vector<std::string> *colors =
|
||||
new std::vector<std::string>(
|
||||
{
|
||||
"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<int, xlnt::string> known_locales()
|
||||
const std::unordered_map<int, std::string> known_locales()
|
||||
{
|
||||
const std::unordered_map<int, xlnt::string> *all =
|
||||
new std::unordered_map<int, xlnt::string>(
|
||||
const std::unordered_map<int, std::string> *all =
|
||||
new std::unordered_map<int, std::string>(
|
||||
{
|
||||
{ 0x401, "Arabic - Saudi Arabia" },
|
||||
{ 0x402, "Bulgarian" },
|
||||
|
@ -324,9 +323,9 @@ const std::unordered_map<int, xlnt::string> 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<xlnt::string> bracket_parts;
|
||||
std::vector<std::string> bracket_parts;
|
||||
|
||||
bool in_quotes = false;
|
||||
bool in_brackets = false;
|
||||
|
||||
const std::vector<xlnt::string> bracket_times = { "h", "hh", "m", "mm", "s", "ss" };
|
||||
const std::vector<std::string> 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<xlnt::string> dates = { "m", "mm", "mmm", "mmmmm", "mmmmmm", "d", "dd", "ddd", "dddd", "yy",
|
||||
const std::vector<std::string> 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<xlnt::string> MonthNames = { "January", "February", "March",
|
||||
const std::vector<std::string> 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<char>(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<long long int>(number))
|
||||
{
|
||||
result = xlnt::string::from(static_cast<long long int>(number));
|
||||
result = std::to_string(static_cast<long long int>(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<string, int> &cell::error_codes()
|
||||
const std::unordered_map<std::string, int> &cell::error_codes()
|
||||
{
|
||||
static const std::unordered_map<string, int> *codes =
|
||||
new std::unordered_map<string, int>({ { "#NULL!", 0 }, { "#DIV/0!", 1 }, { "#VALUE!", 2 },
|
||||
static const std::unordered_map<std::string, int> *codes =
|
||||
new std::unordered_map<std::string, int>({ { "#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<long double>(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<long double>(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<long double>(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<long double>(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<long double>(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<long double>(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<long double>(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<long double>(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<long double>(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<long double>(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<long double>(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<long double>(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<long double>(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<long double>(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 "<Cell " + worksheet(d_->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<std::int8_t>(d_->value_numeric_);
|
||||
}
|
||||
|
||||
template <>
|
||||
XLNT_FUNCTION std::int16_t cell::get_value() const
|
||||
std::int16_t cell::get_value() const
|
||||
{
|
||||
return static_cast<std::int16_t>(d_->value_numeric_);
|
||||
}
|
||||
|
||||
template <>
|
||||
XLNT_FUNCTION std::int32_t cell::get_value() const
|
||||
std::int32_t cell::get_value() const
|
||||
{
|
||||
return static_cast<std::int32_t>(d_->value_numeric_);
|
||||
}
|
||||
|
||||
template <>
|
||||
XLNT_FUNCTION std::int64_t cell::get_value() const
|
||||
std::int64_t cell::get_value() const
|
||||
{
|
||||
return static_cast<std::int64_t>(d_->value_numeric_);
|
||||
}
|
||||
|
||||
template <>
|
||||
XLNT_FUNCTION std::uint8_t cell::get_value() const
|
||||
std::uint8_t cell::get_value() const
|
||||
{
|
||||
return static_cast<std::uint8_t>(d_->value_numeric_);
|
||||
}
|
||||
|
||||
template <>
|
||||
XLNT_FUNCTION std::uint16_t cell::get_value() const
|
||||
std::uint16_t cell::get_value() const
|
||||
{
|
||||
return static_cast<std::uint16_t>(d_->value_numeric_);
|
||||
}
|
||||
|
||||
template <>
|
||||
XLNT_FUNCTION std::uint32_t cell::get_value() const
|
||||
std::uint32_t cell::get_value() const
|
||||
{
|
||||
return static_cast<std::uint32_t>(d_->value_numeric_);
|
||||
}
|
||||
|
||||
template <>
|
||||
XLNT_FUNCTION std::uint64_t cell::get_value() const
|
||||
std::uint64_t cell::get_value() const
|
||||
{
|
||||
return static_cast<std::uint64_t>(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<long long int>(d_->value_numeric_);
|
||||
}
|
||||
#endif
|
||||
|
||||
template <>
|
||||
XLNT_FUNCTION float cell::get_value() const
|
||||
float cell::get_value() const
|
||||
{
|
||||
return static_cast<float>(d_->value_numeric_);
|
||||
}
|
||||
|
||||
template <>
|
||||
XLNT_FUNCTION double cell::get_value() const
|
||||
double cell::get_value() const
|
||||
{
|
||||
return static_cast<double>(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<int>(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<string>(), nf.get_format_string());
|
||||
return format_text(get_value<std::string>(), nf.get_format_string());
|
||||
case cell::type::boolean:
|
||||
return get_value<long double>() == 0 ? "FALSE" : "TRUE";
|
||||
default:
|
||||
|
|
|
@ -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<string, row_t> cell_reference::split_reference(const string &reference_string,
|
||||
std::pair<std::string, row_t> 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<row_t>() };
|
||||
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
|
||||
|
|
|
@ -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_;
|
||||
}
|
||||
|
|
|
@ -145,7 +145,7 @@ public:
|
|||
|
||||
cell.set_value("=");
|
||||
TS_ASSERT(cell.get_data_type() == xlnt::cell::type::string);
|
||||
TS_ASSERT(cell.get_value<xlnt::string>() == "=");
|
||||
TS_ASSERT(cell.get_value<std::string>() == "=");
|
||||
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<xlnt::string>() == "testme");
|
||||
TS_ASSERT(cell.get_value<std::string>() == "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);
|
||||
|
|
|
@ -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<int>(column_string.length()) - 1; i >= 0; i--)
|
||||
{
|
||||
auto index = static_cast<std::size_t>(i);
|
||||
|
||||
if (!is_alpha(column_string[index]))
|
||||
if (!std::isalpha(column_string[static_cast<std::size_t>(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<std::size_t>(i)], std::locale::classic()) - 'A';
|
||||
|
||||
column_index += static_cast<column_t::index_t>((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<int>(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;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,34 +5,33 @@
|
|||
#include <xlnt/cell/cell.hpp>
|
||||
#include <xlnt/cell/comment.hpp>
|
||||
#include <xlnt/cell/types.hpp>
|
||||
#include <xlnt/utils/exceptions.hpp>
|
||||
#include <xlnt/utils/datetime.hpp>
|
||||
#include <xlnt/packaging/relationship.hpp>
|
||||
#include <xlnt/styles/number_format.hpp>
|
||||
#include <xlnt/utils/datetime.hpp>
|
||||
#include <xlnt/utils/exceptions.hpp>
|
||||
#include <xlnt/utils/string.hpp>
|
||||
|
||||
#include <detail/comment_impl.hpp>
|
||||
#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<bool, long double> cast_numeric(const xlnt::string &s)
|
||||
std::pair<bool, long double> 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<bool, long double> cast_percentage(const xlnt::string &s)
|
||||
std::pair<bool, long double> 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<bool, long double> cast_percentage(const xlnt::string &s)
|
|||
return { false, 0 };
|
||||
}
|
||||
|
||||
std::pair<bool, xlnt::time> cast_time(const xlnt::string &s)
|
||||
std::pair<bool, xlnt::time> 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<double>();
|
||||
if (last_colon == std::string::npos) return { false, result };
|
||||
double seconds = std::stod(s.substr(last_colon + 1));
|
||||
result.second = static_cast<int>(seconds);
|
||||
result.microsecond = static_cast<int>((seconds - static_cast<double>(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<int>();
|
||||
result.minute = std::stoi(s.substr(0, first_colon));
|
||||
}
|
||||
else
|
||||
{
|
||||
result.hour = s.substr(0, first_colon).to<int>();
|
||||
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<int>();
|
||||
result.minute = s.substr(first_colon + 1, last_colon - first_colon - 1).to<int>();
|
||||
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_;
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <xlnt/cell/comment.hpp>
|
||||
#include <xlnt/utils/string.hpp>
|
||||
|
||||
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
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
#include <detail/constants.hpp>
|
||||
|
||||
#include <xlnt/xlnt_config.hpp>
|
||||
#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<string, string> constants::Namespaces()
|
||||
const std::unordered_map<std::string, std::string> constants::Namespaces()
|
||||
{
|
||||
const std::unordered_map<string, string> namespaces =
|
||||
const std::unordered_map<std::string, std::string> 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<string, string> 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;
|
||||
}
|
||||
|
|
|
@ -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<string, string> Namespaces();
|
||||
static const std::unordered_map<std::string, std::string> Namespaces();
|
||||
|
||||
static const string Namespace(const string &id);
|
||||
static const std::string Namespace(const std::string &id);
|
||||
};
|
||||
|
||||
} // namespace xlnt
|
||||
|
|
|
@ -63,7 +63,7 @@ struct workbook_impl
|
|||
std::vector<relationship> relationships_;
|
||||
std::vector<relationship> root_relationships_;
|
||||
std::vector<drawing> drawings_;
|
||||
std::vector<string> shared_strings_;
|
||||
std::vector<std::string> shared_strings_;
|
||||
|
||||
document_properties properties_;
|
||||
|
||||
|
|
|
@ -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_t, column_properties> column_properties_;
|
||||
std::unordered_map<row_t, row_properties> row_properties_;
|
||||
string title_;
|
||||
std::string title_;
|
||||
cell_reference freeze_panes_;
|
||||
std::unordered_map<row_t, std::unordered_map<column_t, cell_impl>> cell_map_;
|
||||
std::vector<relationship> relationships_;
|
||||
|
@ -67,7 +67,7 @@ struct worksheet_impl
|
|||
range_reference auto_filter_;
|
||||
margins page_margins_;
|
||||
std::vector<range_reference> merged_cells_;
|
||||
std::unordered_map<string, named_range> named_ranges_;
|
||||
std::unordered_map<std::string, named_range> named_ranges_;
|
||||
std::size_t comment_count_;
|
||||
header_footer header_footer_;
|
||||
};
|
||||
|
|
|
@ -9,7 +9,7 @@ namespace detail {
|
|||
|
||||
struct xml_document_impl
|
||||
{
|
||||
string encoding;
|
||||
std::string encoding;
|
||||
pugi::xml_document doc;
|
||||
};
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ public:
|
|||
{
|
||||
auto path = PathHelper::GetDataDirectory() + "/genuine/empty.xlsx";
|
||||
|
||||
const std::vector<xlnt::string> expected_titles = {"Sheet1 - Text", "Sheet2 - Numbers", "Sheet3 - Formulas", "Sheet4 - Dates"};
|
||||
const std::vector<std::string> 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<xlnt::string> expected_titles = {"Sheet1 - Text", "Sheet2 - Numbers", "Sheet3 - Formulas", "Sheet4 - Dates"};
|
||||
const std::vector<std::string> expected_titles = {"Sheet1 - Text", "Sheet2 - Numbers", "Sheet3 - Formulas", "Sheet4 - Dates"};
|
||||
|
||||
std::size_t i = 0;
|
||||
|
||||
|
|
|
@ -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<TCHAR> 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<xlnt::string> &parts)
|
||||
std::string join_path(const std::vector<std::string> &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<xlnt::string> &parts)
|
|||
|
||||
if (i++ != parts.size() - 1)
|
||||
{
|
||||
joined.append('/');
|
||||
joined.append(1, '/');
|
||||
}
|
||||
}
|
||||
return joined;
|
||||
}
|
||||
|
||||
std::vector<xlnt::string> split_path(const xlnt::string &path, char delim = directory_separator)
|
||||
std::vector<std::string> split_path(const std::string &path, char delim = directory_separator)
|
||||
{
|
||||
std::vector<xlnt::string> split;
|
||||
xlnt::string::size_type previous_index = 0;
|
||||
std::vector<std::string> 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<unsigned char> &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<uint16_t>(comment.length()), std::numeric_limits<uint16_t>::max());
|
||||
buffer_[buffer_.size() - 2] = static_cast<char>(comment_length);
|
||||
buffer_[buffer_.size() - 1] = static_cast<char>(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<std::size_t>(stat.m_comp_size);
|
||||
result.file_size = static_cast<std::size_t>(stat.m_uncomp_size);
|
||||
result.header_offset = static_cast<std::size_t>(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<mz_uint16>(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<mz_uint16>(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<char *>(mz_zip_reader_extract_file_to_heap(archive_.get(), info.filename.data(), &size, 0));
|
||||
static_cast<char *>(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_info> zip_file::infolist()
|
|||
return info;
|
||||
}
|
||||
|
||||
std::vector<string> zip_file::namelist()
|
||||
std::vector<std::string> zip_file::namelist()
|
||||
{
|
||||
std::vector<string> names;
|
||||
std::vector<std::string> names;
|
||||
|
||||
for (auto &info : infolist())
|
||||
{
|
||||
|
@ -608,7 +608,7 @@ std::vector<string> 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<string> &members)
|
||||
void zip_file::extractall(const std::string &path, const std::vector<std::string> &members)
|
||||
{
|
||||
for (auto &member : members)
|
||||
{
|
||||
|
@ -656,7 +656,7 @@ void zip_file::extractall(const string &path, const std::vector<string> &members
|
|||
}
|
||||
}
|
||||
|
||||
void zip_file::extractall(const string &path, const std::vector<zip_info> &members)
|
||||
void zip_file::extractall(const std::string &path, const std::vector<zip_info> &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<bool, string> zip_file::testzip()
|
||||
std::pair<bool, std::string> zip_file::testzip()
|
||||
{
|
||||
if (archive_->m_zip_mode == MZ_ZIP_MODE_INVALID)
|
||||
{
|
||||
|
@ -733,7 +733,7 @@ std::pair<bool, string> 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)
|
||||
{
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
#include <xlnt/packaging/document_properties.hpp>
|
||||
#include <xlnt/packaging/manifest.hpp>
|
||||
#include <xlnt/utils/exceptions.hpp>
|
||||
#include <xlnt/utils/string.hpp>
|
||||
#include <xlnt/workbook/workbook.hpp>
|
||||
#include <xlnt/worksheet/worksheet.hpp>
|
||||
|
||||
|
@ -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<xlnt::string> shared_strings;
|
||||
std::vector<std::string> 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);
|
||||
|
|
|
@ -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")
|
||||
{
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
#include <xlnt/serialization/relationship_serializer.hpp>
|
||||
|
||||
#include <xlnt/packaging/relationship.hpp>
|
||||
#include <xlnt/packaging/zip_file.hpp>
|
||||
#include <xlnt/serialization/xml_document.hpp>
|
||||
#include <xlnt/serialization/xml_node.hpp>
|
||||
#include <xlnt/utils/string.hpp>
|
||||
|
||||
#include <detail/constants.hpp>
|
||||
#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> relationship_serializer::read_relationships(const string &target)
|
||||
std::vector<relationship> 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> 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> relationship_serializer::read_relationships(const stri
|
|||
}
|
||||
|
||||
bool relationship_serializer::write_relationships(const std::vector<relationship> &relationships,
|
||||
const string &target)
|
||||
const std::string &target)
|
||||
{
|
||||
xml_document xml;
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace xlnt {
|
||||
|
||||
xml_document shared_strings_serializer::write_shared_strings(const std::vector<string> &strings)
|
||||
xml_document shared_strings_serializer::write_shared_strings(const std::vector<std::string> &strings)
|
||||
{
|
||||
xml_document xml;
|
||||
|
||||
|
@ -12,7 +12,7 @@ xml_document shared_strings_serializer::write_shared_strings(const std::vector<s
|
|||
|
||||
xml.add_namespace("", "http://schemas.openxmlformats.org/spreadsheetml/2006/main");
|
||||
|
||||
root_node.add_attribute("uniqueCount", string::from(strings.size()));
|
||||
root_node.add_attribute("uniqueCount", std::to_string(strings.size()));
|
||||
|
||||
for (const auto &string : strings)
|
||||
{
|
||||
|
@ -22,13 +22,13 @@ xml_document shared_strings_serializer::write_shared_strings(const std::vector<s
|
|||
return xml;
|
||||
}
|
||||
|
||||
bool shared_strings_serializer::read_shared_strings(const xml_document &xml, std::vector<string> &strings)
|
||||
bool shared_strings_serializer::read_shared_strings(const xml_document &xml, std::vector<std::string> &strings)
|
||||
{
|
||||
strings.clear();
|
||||
|
||||
auto root_node = xml.get_child("sst");
|
||||
|
||||
auto unique_count = root_node.get_attribute("uniqueCount").to<std::size_t>();
|
||||
auto unique_count = std::stoull(root_node.get_attribute("uniqueCount"));
|
||||
|
||||
for (const auto &si_node : root_node.get_children())
|
||||
{
|
||||
|
|
|
@ -8,16 +8,15 @@
|
|||
#include <xlnt/styles/number_format.hpp>
|
||||
#include <xlnt/styles/protection.hpp>
|
||||
#include <xlnt/styles/style.hpp>
|
||||
#include <xlnt/utils/string.hpp>
|
||||
|
||||
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<std::size_t>();
|
||||
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<std::size_t>() : 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<std::size_t>() : 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<std::size_t>() : 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<std::size_t>());
|
||||
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<std::size_t>());
|
||||
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<std::size_t>());
|
||||
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<std::size_t>());
|
||||
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<std::size_t>());
|
||||
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<std::size_t>());
|
||||
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<std::tuple<string, const side, bool>> sides;
|
||||
std::vector<std::tuple<std::string, const side, bool>> 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());
|
||||
}
|
||||
|
||||
|
|
|
@ -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<xlnt::string>());
|
||||
TS_ASSERT_EQUALS("This is cell G5", sheet2.get_cell("G5").get_value<std::string>());
|
||||
TS_ASSERT_EQUALS(18, sheet2.get_cell("D18").get_value<int>());
|
||||
TS_ASSERT_EQUALS(true, sheet2.get_cell("G9").get_value<bool>());
|
||||
TS_ASSERT_EQUALS(false, sheet2.get_cell("G10").get_value<bool>());
|
||||
|
@ -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<std::pair<xlnt::string, xlnt::string>> expected =
|
||||
std::vector<std::pair<std::string, std::string>> expected =
|
||||
{
|
||||
{"/xl/workbook.xml", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"},
|
||||
{"/xl/worksheets/sheet1.xml", "application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"},
|
||||
|
|
|
@ -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 =
|
||||
" <numFmts count=\"1\">"
|
||||
" <numFmt formatCode=\"YYYY\" numFmtId=\"164\"></numFmt>"
|
||||
" </numFmts>";
|
||||
|
|
|
@ -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<xlnt::string>());
|
||||
TS_ASSERT_EQUALS("http://test.com", ws.get_cell("A1").get_value<std::string>());
|
||||
ws.get_cell("A1").set_value("test");
|
||||
TS_ASSERT_EQUALS("test", ws.get_cell("A1").get_value<xlnt::string>());
|
||||
TS_ASSERT_EQUALS("test", ws.get_cell("A1").get_value<std::string>());
|
||||
}
|
||||
|
||||
void test_write_auto_filter()
|
||||
|
|
|
@ -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 =
|
||||
"<workbook xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
|
||||
" <workbookPr/>"
|
||||
" <bookViews>"
|
||||
|
@ -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 =
|
||||
"<root>"
|
||||
"<s:definedName xmlns:s=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" name=\"test_range\">'Sheet'!$A$1:$B$5</s:definedName>"
|
||||
"</root>";
|
||||
|
@ -146,7 +146,7 @@ public:
|
|||
xlnt::workbook_serializer serializer(wb);
|
||||
auto observed = serializer.write_workbook();
|
||||
|
||||
xlnt::string expected =
|
||||
std::string expected =
|
||||
"<workbook xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">"
|
||||
" <workbookPr codeName=\"MyWB\"/>"
|
||||
" <bookViews>"
|
||||
|
@ -171,7 +171,7 @@ public:
|
|||
xlnt::xml_document observed;
|
||||
observed.from_string(archive.read("_rels/.rels"));
|
||||
|
||||
xlnt::string expected =
|
||||
std::string expected =
|
||||
"<Relationships xmlns=\"http://schemas.openxmlformats.org/package/2006/relationships\">"
|
||||
" <Relationship Id=\"rId1\" Target=\"xl/workbook.xml\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument\"/>"
|
||||
" <Relationship Id=\"rId2\" Target=\"docProps/core.xml\" Type=\"http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties\"/>"
|
||||
|
|
|
@ -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_element> 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_scheme> font_schemes = {
|
||||
|
|
|
@ -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<int>();
|
||||
result.month = string.substr(separator_index + 1, string.find('-', separator_index + 1)).to<int>();
|
||||
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<int>();
|
||||
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<int>();
|
||||
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<int>();
|
||||
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<int>();
|
||||
|
||||
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<string::size_type>(first_digit + 1));
|
||||
std::size_t sheet_index = sheet_index_string.to<std::size_t>() - 1;
|
||||
sheet_index_string = sheet_index_string.substr(static_cast<std::string::size_type>(first_digit + 1));
|
||||
std::size_t sheet_index = static_cast<std::size_t>(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);
|
||||
}
|
||||
|
|
|
@ -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<std::size_t>();
|
||||
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<row_t>();
|
||||
auto row_index = static_cast<row_t>(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<long double>();
|
||||
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<column_t>(span_string.substr(0, colon_index).to<column_t::index_t>());
|
||||
max_column = static_cast<column_t>(span_string.substr(colon_index + 1).to<column_t::index_t>());
|
||||
min_column = static_cast<column_t>(std::stoll(span_string.substr(0, colon_index)));
|
||||
max_column = static_cast<column_t>(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<std::size_t>(has_style ? cell_node.get_attribute("s").to<std::size_t>() : 0ULL);
|
||||
auto style_id = static_cast<std::size_t>(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<std::size_t>();
|
||||
auto shared_string_index = static_cast<std::size_t>(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<long double>());
|
||||
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<column_t>(col_node.get_attribute("min").to<column_t::index_t>());
|
||||
auto max = static_cast<column_t>(col_node.get_attribute("max").to<column_t::index_t>());
|
||||
auto width = col_node.get_attribute("width").to<long double>();
|
||||
auto min = static_cast<column_t>(std::stoull(col_node.get_attribute("min")));
|
||||
auto max = static_cast<column_t>(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<std::size_t>(col_node.has_attribute("style") ? col_node.get_attribute("style").to<std::size_t>() : 0ULL);
|
||||
auto column_style = static_cast<std::size_t>(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<string, string> hyperlink_references;
|
||||
std::unordered_map<std::string, std::string> 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<long long int>(height)) + ".0");
|
||||
row_node.add_attribute("ht", std::to_string(static_cast<long long int>(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<string>())
|
||||
if (shared_strings[i] == cell.get_value<std::string>())
|
||||
{
|
||||
match_index = static_cast<int>(i);
|
||||
break;
|
||||
|
@ -422,7 +422,7 @@ xml_document worksheet_serializer::write_worksheet() const
|
|||
|
||||
if (match_index == -1)
|
||||
{
|
||||
if (cell.get_value<string>().empty())
|
||||
if (cell.get_value<std::string>().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<string>());
|
||||
inline_string_node.add_child("t").set_text(cell.get_value<std::string>());
|
||||
}
|
||||
}
|
||||
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<long double>()))
|
||||
{
|
||||
value_node.set_text(string::from(cell.get_value<long long>()));
|
||||
value_node.set_text(std::to_string(cell.get_value<long long>()));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -472,7 +472,7 @@ xml_document worksheet_serializer::write_worksheet() const
|
|||
ss.precision(20);
|
||||
ss << cell.get_value<long double>();
|
||||
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<int>(sheet_.get_page_setup().get_paper_size())));
|
||||
std::to_string(static_cast<int>(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";
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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> xml_node::get_children() const
|
||||
|
@ -69,7 +69,7 @@ const std::vector<xml_node> 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::string_pair> xml_node::get_attributes() const
|
||||
|
@ -95,43 +95,43 @@ const std::vector<xml_node::string_pair> xml_node::get_attributes() const
|
|||
|
||||
for (auto attr : d_->node.attributes())
|
||||
{
|
||||
attributes.push_back(std::make_pair<string, string>(attr.name(), attr.value()));
|
||||
attributes.push_back(std::make_pair<std::string, std::string>(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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -6,10 +6,10 @@
|
|||
|
||||
namespace {
|
||||
|
||||
const std::unordered_map<std::size_t, xlnt::string> &builtin_formats()
|
||||
const std::unordered_map<std::size_t, std::string> &builtin_formats()
|
||||
{
|
||||
static const std::unordered_map<std::size_t, xlnt::string> *formats =
|
||||
new std::unordered_map<std::size_t, xlnt::string>
|
||||
static const std::unordered_map<std::size_t, std::string> *formats =
|
||||
new std::unordered_map<std::size_t, std::string>
|
||||
({
|
||||
{ 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;
|
||||
|
|
|
@ -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<int>();
|
||||
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<int>();
|
||||
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<int>();
|
||||
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()
|
||||
|
|
|
@ -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() ? "<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<unsigned char>(c)) + ")")
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -1,930 +0,0 @@
|
|||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
//TODO: make this conditional on XLNT_STD_STRING once std::sto* functions are replaced
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <utf8.h>
|
||||
|
||||
#include <xlnt/utils/string.hpp>
|
||||
|
||||
namespace {
|
||||
|
||||
template<typename T>
|
||||
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<int>(index_) + offset;
|
||||
new_index = std::max<int>(0, std::min<int>(static_cast<int>(parent_->length()), new_index));
|
||||
index_ = static_cast<std::size_t>(new_index);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
xlnt::string::iterator xlnt::string::iterator::operator+(int offset)
|
||||
{
|
||||
iterator copy = *this;
|
||||
|
||||
auto new_index = static_cast<int>(index_) + offset;
|
||||
new_index = std::max<int>(0, std::min<int>(static_cast<int>(parent_->length()), new_index));
|
||||
copy.index_ = static_cast<std::size_t>(new_index);
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
xlnt::string::const_iterator xlnt::string::const_iterator::operator+(int offset)
|
||||
{
|
||||
const_iterator copy = *this;
|
||||
|
||||
auto new_index = static_cast<int>(index_) + offset;
|
||||
new_index = std::max<int>(0, std::min<int>(static_cast<int>(parent_->length()), new_index));
|
||||
copy.index_ = static_cast<std::size_t>(new_index);
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
string::string(size_type initial_size)
|
||||
: data_(new std::vector<char>),
|
||||
code_point_byte_offsets_(new std::unordered_map<size_type, size_type>)
|
||||
{
|
||||
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<char>(*str.data_)),
|
||||
code_point_byte_offsets_(new std::unordered_map<size_type, size_type>(*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<int>(offset), begin() + static_cast<int>(offset + len));
|
||||
}
|
||||
|
||||
return string(begin() + static_cast<int>(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<int>(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<code_point>(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<int>(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<code_point>(c), offset);
|
||||
}
|
||||
|
||||
string::size_type string::find_last_of(const string &str, size_type offset) const
|
||||
{
|
||||
auto stop = begin() + static_cast<int>(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<int>(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<int>(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<int>(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<std::string> 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<char>(c));
|
||||
return;
|
||||
}
|
||||
|
||||
data_->pop_back();
|
||||
|
||||
std::array<char, 4> 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<char>(c));
|
||||
return;
|
||||
}
|
||||
|
||||
data_->pop_back();
|
||||
|
||||
std::array<char, 4> 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<char>(c));
|
||||
return;
|
||||
}
|
||||
|
||||
data_->pop_back();
|
||||
|
||||
std::array<char, 4> 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<byte, 4> 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<int>(data_end - data_start);
|
||||
int difference = static_cast<int>(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
|
|
@ -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<unsigned char> 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;
|
||||
};
|
||||
|
|
|
@ -12,13 +12,13 @@ namespace {
|
|||
/// <remark>
|
||||
/// This should maybe be in a utility header so it can be used elsewhere.
|
||||
/// </remarks>
|
||||
std::vector<xlnt::string> split_string(const xlnt::string &string, char delim)
|
||||
std::vector<std::string> split_string(const std::string &string, char delim)
|
||||
{
|
||||
std::vector<xlnt::string> split;
|
||||
xlnt::string::size_type previous_index = 0;
|
||||
std::vector<std::string> 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<xlnt::string> 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<xlnt::string> split_string(const xlnt::string &string, char delim)
|
|||
|
||||
namespace xlnt {
|
||||
|
||||
std::vector<std::pair<string, string>> split_named_range(const string &named_range_string)
|
||||
std::vector<std::pair<std::string, std::string>> split_named_range(const std::string &named_range_string)
|
||||
{
|
||||
std::vector<std::pair<string, string>> final;
|
||||
std::vector<std::pair<std::string, std::string>> 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<named_range::target> &targets)
|
||||
named_range::named_range(const std::string &name, const std::vector<named_range::target> &targets)
|
||||
: name_(name), targets_(targets)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -10,9 +10,9 @@ class test_named_range : public CxxTest::TestSuite
|
|||
public:
|
||||
void test_split()
|
||||
{
|
||||
using string_pair = std::pair<xlnt::string, xlnt::string>;
|
||||
using string_pair = std::pair<std::string, std::string>;
|
||||
using string_pair_vector = std::vector<string_pair>;
|
||||
using expected_pair = std::pair<xlnt::string, string_pair_vector>;
|
||||
using expected_pair = std::pair<std::string, string_pair_vector>;
|
||||
|
||||
std::vector<expected_pair> expected_pairs =
|
||||
{
|
||||
|
|
|
@ -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<xlnt::string> names = {"NewSheet", "NewSheet1", "NewSheet2", "NewSheet3", "NewSheet4", "NewSheet5"};
|
||||
std::vector<std::string> 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);
|
||||
|
|
|
@ -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<unsigned char> &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<std::size_t>(iter - sheet_index_string.begin());
|
||||
sheet_index_string = sheet_index_string.substr(first_digit + 1);
|
||||
auto sheet_index = sheet_index_string.to<std::size_t>() - 1;
|
||||
auto sheet_index = static_cast<std::size_t>(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<string> workbook::get_sheet_names() const
|
||||
std::vector<std::string> workbook::get_sheet_names() const
|
||||
{
|
||||
std::vector<string> names;
|
||||
std::vector<std::string> names;
|
||||
|
||||
for (auto ws : *this)
|
||||
{
|
||||
|
@ -450,7 +450,7 @@ std::vector<string> 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<unsigned char> &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<relationship> &workbook::get_root_relationships() const
|
|||
return d_->root_relationships_;
|
||||
}
|
||||
|
||||
std::vector<string> &workbook::get_shared_strings()
|
||||
std::vector<std::string> &workbook::get_shared_strings()
|
||||
{
|
||||
return d_->shared_strings_;
|
||||
}
|
||||
|
||||
const std::vector<string> &workbook::get_shared_strings() const
|
||||
const std::vector<std::string> &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
|
||||
|
|
|
@ -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<column_t::index_t>(ref_.get_top_left().get_column().index + vector_index)),
|
||||
range_reference reference(
|
||||
static_cast<column_t>(static_cast<std::size_t>(ref_.get_top_left().get_column().index) + vector_index),
|
||||
ref_.get_top_left().get_row(),
|
||||
column_t(static_cast<column_t::index_t>(ref_.get_top_left().get_column().index + vector_index)),
|
||||
static_cast<column_t>(static_cast<std::size_t>(ref_.get_top_left().get_column().index) + vector_index),
|
||||
ref_.get_bottom_right().get_row());
|
||||
|
||||
return cell_vector(ws_, reference, order_);
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user