<commit_before>// Copyright 2017 Google Inc.
//
// Licensed 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 <sys/types.h>
#include <sys/stat.h>
#include <Qt/qregexp.h>
#include <gstAssetManager.h>
#include <khConstants.h>
#include <vector>
#include <exception>
#include "gstAssetGroup.h"

class SuffixNotFound : public std::exception
{
private:
    std::string aname;

public:
    SuffixNotFound(const std::string& _aname) : aname(_aname) {}

    const char* what() const noexcept
    {
        std::string ret { "No suffix found for " };
        ret += aname;
        return ret.c_str();
    }
};

const char* shortAssetName(const char* n) {

  static const std::vector<std::string> suffixes =
  {
      kVectorAssetSuffix, kImageryAssetSuffix, kMercatorImageryAssetSuffix,
      kTerrainAssetSuffix, kVectorProjectSuffix, kImageryProjectSuffix,
      kMercatorImageryProjectSuffix, kTerrainProjectSuffix,
      kDatabaseSuffix, kMapLayerSuffix, kMapProjectSuffix,
      kMapDatabaseSuffix, kMercatorMapDatabaseSuffix, kVectorLayerSuffix
  };

  std::string saname { n };

  for (const auto& elem : suffixes)
  {
      auto pos = saname.rfind(elem);
      if (pos != std::string::npos)
      {
          return saname.substr(0,pos).c_str();
      }
  }

  throw SuffixNotFound(saname);
}

bool isAssetPath(const QString& str) {
  static QRegExp rx(".*\\.k[vit](asset|project)$|"
                    ".*\\.k[i](masset|mproject)$|"
                    ".*\\.kdatabase$|"
                    ".*\\.km(layer|project|database|mdatabase)|"
                    ".*\\.kvlayer", true, false);
  return rx.exactMatch(str);
}

// -----------------------------------------------------------------------------

gstAssetHandleImpl::gstAssetHandleImpl(const gstAssetFolder& f,
                                       const QString& n)
    : parent_folder_(f), name_(n) {
}

gstAssetHandleImpl::~gstAssetHandleImpl() {
}

const gstAssetFolder &gstAssetHandleImpl::getParentFolder() const {
  return parent_folder_;
}

bool gstAssetHandleImpl::isValid() const {
  return (parent_folder_.isValid() &&
          AssetDefs::HaveAssetFile(std::string(relativePath().latin1())) &&
          getAsset()->type != AssetDefs::Invalid);
}

Asset gstAssetHandleImpl::getAsset() const {
  std::string rpath { relativePath().toUtf8().constData() };
  return Asset(rpath);
}

QString gstAssetHandleImpl::getName() const {
  return name_;
}

QString gstAssetHandleImpl::relativePath() const {
  QString path;
<commit_msg>refactored to use std::string, looking into previous jumbled text issues to see if this fixes that as well<commit_after>// Copyright 2017 Google Inc.
//
// Licensed 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 <sys/types.h>
#include <sys/stat.h>
#include <Qt/qregexp.h>
#include <gstAssetManager.h>
#include <khConstants.h>
#include <exception>
#include "gstAssetGroup.h"

class SuffixNotFound : public std::exception
{
private:
    std::string aname;

public:
    SuffixNotFound(const std::string& _aname) : aname(_aname) {}

    const char* what() const noexcept
    {
        std::string ret { "No suffix found for " };
        ret += aname;
        return ret.c_str();
    }
};

const char* shortAssetName(const char* n) {

  static const std::vector<std::string> suffixes =
  {
      kVectorAssetSuffix, kImageryAssetSuffix, kMercatorImageryAssetSuffix,
      kTerrainAssetSuffix, kVectorProjectSuffix, kImageryProjectSuffix,
      kMercatorImageryProjectSuffix, kTerrainProjectSuffix,
      kDatabaseSuffix, kMapLayerSuffix, kMapProjectSuffix,
      kMapDatabaseSuffix, kMercatorMapDatabaseSuffix, kVectorLayerSuffix
  };

  std::string saname { n };

  for (const auto& elem : suffixes)
  {
      auto pos = saname.rfind(elem);
      if (pos != std::string::npos)
      {
          return saname.substr(0,pos).c_str();
      }
  }

  throw SuffixNotFound(saname);
}

bool isAssetPath(const QString& str) {
  static QRegExp rx(".*\\.k[vit](asset|project)$|"
                    ".*\\.k[i](masset|mproject)$|"
                    ".*\\.kdatabase$|"
                    ".*\\.km(layer|project|database|mdatabase)|"
                    ".*\\.kvlayer", true, false);
  return rx.exactMatch(str);
}

// -----------------------------------------------------------------------------

gstAssetHandleImpl::gstAssetHandleImpl(const gstAssetFolder& f,
                                       const QString& n)
    : parent_folder_(f), name_(n) {
}

gstAssetHandleImpl::~gstAssetHandleImpl() {
}

const gstAssetFolder &gstAssetHandleImpl::getParentFolder() const {
  return parent_folder_;
}

bool gstAssetHandleImpl::isValid() const {
  return (parent_folder_.isValid() &&
          AssetDefs::HaveAssetFile(std::string(relativePath().latin1())) &&
          getAsset()->type != AssetDefs::Invalid);
}

Asset gstAssetHandleImpl::getAsset() const {
  std::string rpath { relativePath().toStdString() };
  return Asset(rpath);
}

QString gstAssetHandleImpl::getName() const {
  return name_;
}

QString gstAssetHandleImpl::relativePath() const {
  QString path;

{'fraction_non_alphanumeric': 0.14636963696369637, 'fraction_numerical': 0.0034653465346534654, 'mean_word_length': 3.0165672630881377, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1454262', 'n_tokens_mistral': 1871, 'n_tokens_neox': 1831, 'n_words': 461}