Repository: apache/arrow
File: cpp/src/arrow/flight/sql/odbc/odbc_impl/flight_sql_statement_get_tables.cc (C++)

Code before:
// 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/flight/sql/odbc/odbc_impl/flight_sql_statement_get_tables.h"

#include "arrow/flight/api.h"
#include "arrow/flight/sql/odbc/odbc_impl/flight_sql_result_set.h"
#include "arrow/flight/sql/odbc/odbc_impl/platform.h"
#include "arrow/flight/sql/odbc/odbc_impl/record_batch_transformer.h"
#include "arrow/flight/sql/odbc/odbc_impl/util.h"
#include "arrow/flight/types.h"
#include "arrow/util/string.h"

namespace arrow::flight::sql::odbc {

using arrow::Result;

static void AddTableType(std::string& table_type, std::vector<std::string>& table_types) {
  std::string trimmed_type = arrow::internal::TrimString(table_type);

  // Only put the string if the trimmed result is non-empty
  if (trimmed_type.length() > 0) {
    table_types.emplace_back(trimmed_type);
  }
}

void ParseTableTypes(const std::string& table_type,
                     std::vector<std::string>& table_types) {
  bool encountered = false;  // for checking if there is a single quote
  std::string curr_parse;    // the current string

  for (char temp : table_type) {  // while still in the string
    switch (temp) {               // switch depending on the character
      case '\'':                  // if the character is a single quote
        // track when we've encountered a single opening quote
        // and are still looking for the closing quote
        encountered = !encountered;
        break;
      case ',':                                   // if it is a comma
        if (!encountered) {                       // if we have not found a single quote
          AddTableType(curr_parse, table_types);  // put current string into vector
          curr_parse = "";                        // reset the current string
          break;
        }
        [[fallthrough]];
      default:                       // if it is a normal character
        curr_parse.push_back(temp);  // put the character into the current string

Review comment (suggestion):
Perhaps it would be better as `if (!trimmed_type.empty())`

Code after:
// 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/flight/sql/odbc/odbc_impl/flight_sql_statement_get_tables.h"

#include "arrow/flight/api.h"
#include "arrow/flight/sql/odbc/odbc_impl/flight_sql_result_set.h"
#include "arrow/flight/sql/odbc/odbc_impl/platform.h"
#include "arrow/flight/sql/odbc/odbc_impl/record_batch_transformer.h"
#include "arrow/flight/sql/odbc/odbc_impl/util.h"
#include "arrow/flight/types.h"
#include "arrow/util/string.h"

namespace arrow::flight::sql::odbc {

using arrow::Result;

static void AddTableType(std::string& table_type, std::vector<std::string>& table_types) {
  std::string trimmed_type = arrow::internal::TrimString(table_type);

  // Only put the string if the trimmed result is non-empty
  if (!trimmed_type.empty()) {
    table_types.emplace_back(std::move(trimmed_type));
  }
}

void ParseTableTypes(const std::string& table_type,
                     std::vector<std::string>& table_types) {
  bool encountered = false;  // for checking if there is a single quote
  std::string curr_parse;    // the current string

  for (char temp : table_type) {  // while still in the string
    switch (temp) {               // switch depending on the character
      case '\'':                  // if the character is a single quote
        // track when we've encountered a single opening quote
        // and are still looking for the closing quote
        encountered = !encountered;
        break;
      case ',':                                   // if it is a comma
        if (!encountered) {                       // if we have not found a single quote
          AddTableType(curr_parse, table_types);  // put current string into vector
          curr_parse = "";                        // reset the current string
          break;
        }
        [[fallthrough]];
      default:                       // if it is a normal character
        curr_parse.push_back(temp);  // put the character into the current string