Make index zero-base, and also support relative index.
| 828 | |
| 829 | // Make index zero-base, and also support relative index. |
| 830 | static inline bool fixIndex(int idx, int n, int *ret, bool allow_zero, |
| 831 | const warning_context &context) { |
| 832 | if (!ret) { |
| 833 | return false; |
| 834 | } |
| 835 | |
| 836 | if (idx > 0) { |
| 837 | (*ret) = idx - 1; |
| 838 | return true; |
| 839 | } |
| 840 | |
| 841 | if (idx == 0) { |
| 842 | // zero is not allowed according to the spec. |
| 843 | if (context.warn) { |
| 844 | (*context.warn) += |
| 845 | "A zero value index found (will have a value of -1 for normal and " |
| 846 | "tex indices. Line " + |
| 847 | toString(context.line_number) + ").\n"; |
| 848 | } |
| 849 | |
| 850 | (*ret) = idx - 1; |
| 851 | return allow_zero; |
| 852 | } |
| 853 | |
| 854 | if (idx < 0) { |
| 855 | (*ret) = n + idx; // negative value = relative |
| 856 | if ((*ret) < 0) { |
| 857 | return false; // invalid relative index |
| 858 | } |
| 859 | return true; |
| 860 | } |
| 861 | |
| 862 | return false; // never reach here. |
| 863 | } |
| 864 | |
| 865 | static inline std::string parseString(const char **token) { |
| 866 | std::string s; |
no test coverage detected