constants.cpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. // Copyright (c) 2014-2021 Thomas Fussell
  2. //
  3. // Permission is hereby granted, free of charge, to any person obtaining a copy
  4. // of this software and associated documentation files (the "Software"), to deal
  5. // in the Software without restriction, including without limitation the rights
  6. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. // copies of the Software, and to permit persons to whom the Software is
  8. // furnished to do so, subject to the following conditions:
  9. //
  10. // The above copyright notice and this permission notice shall be included in
  11. // all copies or substantial portions of the Software.
  12. //
  13. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. // THE SOFTWARE
  20. //
  21. // @license: http://www.opensource.org/licenses/mit-license.php
  22. // @author: see AUTHORS file
  23. #include <limits>
  24. #include <xlnt/xlnt_config.hpp>
  25. #include <xlnt/utils/exceptions.hpp>
  26. #include <detail/constants.hpp>
  27. namespace xlnt {
  28. row_t constants::min_row()
  29. {
  30. return 1;
  31. }
  32. row_t constants::max_row()
  33. {
  34. return std::numeric_limits<row_t>::max();
  35. }
  36. const column_t constants::min_column()
  37. {
  38. return column_t(1);
  39. }
  40. const column_t constants::max_column()
  41. {
  42. return column_t(std::numeric_limits<column_t::index_t>::max());
  43. }
  44. // constants
  45. const path constants::package_properties()
  46. {
  47. return path("docProps");
  48. }
  49. const path constants::package_xl()
  50. {
  51. return path("/xl");
  52. }
  53. const path constants::package_root_rels()
  54. {
  55. return path(std::string("_rels"));
  56. }
  57. const path constants::package_theme()
  58. {
  59. return package_xl().append("theme");
  60. }
  61. const path constants::package_worksheets()
  62. {
  63. return package_xl().append("worksheets");
  64. }
  65. const path constants::package_drawings()
  66. {
  67. return package_xl().append("drawings");
  68. }
  69. const path constants::part_content_types()
  70. {
  71. return path("[Content_Types].xml");
  72. }
  73. const path constants::part_root_relationships()
  74. {
  75. return package_root_rels().append(".rels");
  76. }
  77. const path constants::part_core()
  78. {
  79. return package_properties().append("core.xml");
  80. }
  81. const path constants::part_app()
  82. {
  83. return package_properties().append("app.xml");
  84. }
  85. const path constants::part_workbook()
  86. {
  87. return package_xl().append("workbook.xml");
  88. }
  89. const path constants::part_styles()
  90. {
  91. return package_xl().append("styles.xml");
  92. }
  93. const path constants::part_theme()
  94. {
  95. return package_theme().append("theme1.xml");
  96. }
  97. const path constants::part_shared_strings()
  98. {
  99. return package_xl().append("sharedStrings.xml");
  100. }
  101. const std::unordered_map<std::string, std::string> &constants::namespaces()
  102. {
  103. static const std::unordered_map<std::string, std::string> namespaces =
  104. std::unordered_map<std::string, std::string>{
  105. {"spreadsheetml", "http://schemas.openxmlformats.org/spreadsheetml/2006/main"},
  106. {"content-types", "http://schemas.openxmlformats.org/package/2006/content-types"},
  107. {"relationships", "http://schemas.openxmlformats.org/package/2006/relationships"},
  108. {"drawingml", "http://schemas.openxmlformats.org/drawingml/2006/main"},
  109. {"workbook", "http://schemas.openxmlformats.org/spreadsheetml/2006/main"},
  110. {"core-properties", "http://schemas.openxmlformats.org/package/2006/metadata/core-properties"},
  111. {"extended-properties", "http://schemas.openxmlformats.org/officeDocument/2006/extended-properties"},
  112. {"custom-properties", "http://schemas.openxmlformats.org/officeDocument/2006/custom-properties"},
  113. {"encryption", "http://schemas.microsoft.com/office/2006/encryption"},
  114. {"encryption-password", "http://schemas.microsoft.com/office/2006/keyEncryptor/password"},
  115. {"encryption-certificate", "http://schemas.microsoft.com/office/2006/keyEncryptor/certificate"},
  116. {"dc", "http://purl.org/dc/elements/1.1/"},
  117. {"dcterms", "http://purl.org/dc/terms/"},
  118. {"dcmitype", "http://purl.org/dc/dcmitype/"},
  119. {"mc", "http://schemas.openxmlformats.org/markup-compatibility/2006"},
  120. {"mx", "http://schemas.microsoft.com/office/mac/excel/2008/main"},
  121. {"r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships"},
  122. {"thm15", "http://schemas.microsoft.com/office/thememl/2012/main"},
  123. {"vt", "http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes"},
  124. {"x14", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main"},
  125. {"x14ac", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac"},
  126. {"x15", "http://schemas.microsoft.com/office/spreadsheetml/2010/11/main"},
  127. {"x15ac", "http://schemas.microsoft.com/office/spreadsheetml/2010/11/ac"},
  128. {"xml", "http://www.w3.org/XML/1998/namespace"},
  129. {"xsi", "http://www.w3.org/2001/XMLSchema-instance"},
  130. {"a", "http://schemas.openxmlformats.org/drawingml/2006/main"},
  131. {"xdr", "http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing"},
  132. {"loext", "http://schemas.libreoffice.org/"}};
  133. return namespaces;
  134. }
  135. const std::string &constants::ns(const std::string &id)
  136. {
  137. auto match = namespaces().find(id);
  138. if (match == namespaces().end())
  139. {
  140. throw xlnt::exception("bad namespace");
  141. }
  142. return match->second;
  143. }
  144. } // namespace xlnt