28#include "../utility/utility.hpp"
29#include "../algorithm/algorithm.hpp"
30#include "../macros.hpp"
35hi_export_module(hikogui.layout.spreadsheet_address);
37hi_export
namespace hi::inline
v1 {
41 bool column_nr_is_relative =
true;
43 bool row_nr_is_relative =
true;
46 if (address.starts_with(
"$")) {
47 column_nr_is_relative =
false;
48 address.remove_prefix(1);
51 while (!address.empty() && is_alpha(address.front())) {
53 column_nr += address.front() - (is_upper(address.front()) ?
'A' :
'a') + 1;
54 address.remove_prefix(1);
57 if (address.starts_with(
"$")) {
58 row_nr_is_relative =
false;
59 address.remove_prefix(1);
62 while (!address.empty() && is_digit(address.front())) {
64 row_nr += address.front() -
'0';
65 address.remove_prefix(1);
68 return {column_nr_is_relative, column_nr - 1, row_nr_is_relative, row_nr - 1};
82 auto [column_nr_is_relative, column_nr, row_nr_is_relative, row_nr] = _parse_spreadsheet_address(address);
83 hi_check(address.empty(),
"Extra characters in spread sheet address {}", address);
85 if (column_nr_is_relative) {
86 column_nr += start_column_nr;
88 if (row_nr_is_relative) {
89 row_nr += start_row_nr;
91 return {column_nr, row_nr};
105 auto [column_nr_is_relative1, column_nr1, row_nr_is_relative1, row_nr1] = _parse_spreadsheet_address(address);
106 if (column_nr_is_relative1) {
107 column_nr1 += start_column_nr;
109 if (row_nr_is_relative1) {
110 row_nr1 += start_row_nr;
113 if (address.starts_with(
":")) {
114 address.remove_prefix(1);
115 auto [column_nr_is_relative2, column_nr2, row_nr_is_relative2, row_nr2] = _parse_spreadsheet_address(address);
116 hi_check(address.empty(),
"Extra characters in spread sheet address {}", address);
118 if (column_nr_is_relative2) {
119 column_nr2 += start_column_nr;
121 if (row_nr_is_relative2) {
122 row_nr2 += start_row_nr;
125 hi_check(column_nr1 <= column_nr2,
"Column range must be in ascending direction");
126 hi_check(row_nr1 <= row_nr2,
"Column range must be in ascending direction");
127 return {column_nr1, row_nr1, column_nr2 + 1, row_nr2 + 1};
130 hi_check(address.empty(),
"Extra characters in spread sheet address {}", address);
131 return {column_nr1, row_nr1, column_nr1 + 1, row_nr1 + 1};
std::pair< std::size_t, std::size_t > parse_spreadsheet_address(std::string_view address, std::size_t start_column_nr=0, std::size_t start_row_nr=0)
Parse a spreadsheet address.
Definition spreadsheet_address.hpp:80
std::tuple< std::size_t, std::size_t, std::size_t, std::size_t > parse_spreadsheet_range(std::string_view address, std::size_t start_column_nr=0, std::size_t start_row_nr=0)
Parse a spreadsheet range.
Definition spreadsheet_address.hpp:103
DOXYGEN BUG.
Definition algorithm_misc.hpp:20