sgilmore10 commented on code in PR #37725:
URL: https://github.com/apache/arrow/pull/37725#discussion_r1327612882


##########
matlab/src/cpp/arrow/matlab/index/validate.cc:
##########
@@ -0,0 +1,56 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "arrow/matlab/index/validate.h"
+
+#include <sstream>
+
+namespace arrow::matlab::index {
+
+    namespace {
+        std::string makeZeroFieldsErrorMessage() {
+            return "Numeric indexing using the field method is not supported 
for objects with zero fields.";
+        }
+
+        std::string makeInvalidNumericFieldIndexErrorMessage(const int32_t 
matlab_index, const int32_t num_fields) {
+            std::stringstream error_message_stream;
+            error_message_stream << "Invalid field index: ";
+            // matlab uses 1-based indexing
+            error_message_stream << matlab_index;
+            error_message_stream << ". Field index must be between 1 and the 
number of fields (";
+            error_message_stream << num_fields;
+            error_message_stream << ").";
+            return error_message_stream.str();
+        }
+    } // anonymous namespace 
+
+    arrow::Status validateNonEmptyFields(const int32_t num_fields) {
+        if (num_fields == 0) {
+            const auto msg = makeZeroFieldsErrorMessage();
+            return arrow::Status::Invalid(std::move(msg));
+        }
+        return arrow::Status::OK();
+    }
+
+    arrow::Status validateNumericFieldIndexInRange(const int32_t matlab_index, 
const int32_t num_fields) {
+        if (matlab_index < 1 || matlab_index > num_fields) {
+            const auto msg = 
makeInvalidNumericFieldIndexErrorMessage(matlab_index, num_fields);

Review Comment:
   Good point! I'll also rename the `validateNumericFieldIndexInRange` to 
`validateInRange`. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to