MCPcopy Create free account
hub / github.com/apache/arrow / FormatStringParser

Class FormatStringParser

cpp/src/arrow/c/bridge.cc:844–935  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

842}
843
844class FormatStringParser {
845 public:
846 FormatStringParser() = default;
847
848 explicit FormatStringParser(std::string_view v) : view_(v), index_(0) {}
849
850 bool AtEnd() const { return index_ >= view_.length(); }
851
852 char Next() { return view_[index_++]; }
853
854 std::string_view Rest() { return view_.substr(index_); }
855
856 Status CheckNext(char c) {
857 if (AtEnd() || Next() != c) {
858 return Invalid();
859 }
860 return Status::OK();
861 }
862
863 Status CheckHasNext() {
864 if (AtEnd()) {
865 return Invalid();
866 }
867 return Status::OK();
868 }
869
870 Status CheckAtEnd() {
871 if (!AtEnd()) {
872 return Invalid();
873 }
874 return Status::OK();
875 }
876
877 template <typename IntType = int32_t>
878 Result<IntType> ParseInt(std::string_view v) {
879 using ArrowIntType = typename CTypeTraits<IntType>::ArrowType;
880 IntType value;
881 if (!internal::ParseValue<ArrowIntType>(v.data(), v.size(), &value)) {
882 return Invalid();
883 }
884 return value;
885 }
886
887 Result<TimeUnit::type> ParseTimeUnit() {
888 RETURN_NOT_OK(CheckHasNext());
889 switch (Next()) {
890 case 's':
891 return TimeUnit::SECOND;
892 case 'm':
893 return TimeUnit::MILLI;
894 case 'u':
895 return TimeUnit::MICRO;
896 case 'n':
897 return TimeUnit::NANO;
898 default:
899 return Invalid();
900 }
901 }

Callers 1

ProcessFormatMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected