<commit_before>/*
 * FileSystem.cpp
 *
 *  Created on: Jun 20, 2014
 *      Author: Pimenta
 */

// this
#include "FileSystem.hpp"

using namespace std;
using namespace helpers;

map<string, FileSystem::Folder> FileSystem::folders;

void FileSystem::init() {
  folders.clear();
  folders["root"];
}

bool FileSystem::parseName(const string& name) {
  static set<char> allowedChars;
  static StaticInitializer staticInitializar([&]() {
    for (char c = '0'; c <= '9'; c++)
      allowedChars.insert(c);
    for (char c = 'a'; c <= 'z'; c++)
      allowedChars.insert(c);
    for (char c = 'A'; c <= 'Z'; c++)
      allowedChars.insert(c);
    allowedChars.insert('_');
    allowedChars.insert('-');
    allowedChars.insert('+');
    allowedChars.insert('.');
  });
  if (!name.size())
    return false;
  for (int i = 0; i < int(name.size()); i++) {
    if (allowedChars.find(name[i]) != allowedChars.end())
      return false;
  }
  return true;
}

bool FileSystem::parsePath(const string& path) {
  if (!path.size())
    return false;
  list<string> atoms = explode(path, '/');
  string tmp;
  auto it = atoms.begin();
  for (int i = 0; i < int(atoms.size()) - 1; i++) {
    if (!parseName(*it))
      return false;
    tmp += (*it);
    tmp += '/';
    it++;
  }
  if (it != atoms.end()) {
    if (!parseName(*it))
      return false;
    tmp += (*it);
  }
  return tmp == path;
}

bool FileSystem::createFolder(const string& fullPath) {
  if (!parsePath(fullPath)) // if the path is invalid
    return false;
  if (folders.find(fullPath) != folders.end()) // if the folder already exists
    return false;
  pair<string, string> divided = divide(fullPath, '/');
  auto motherFolder = folders.find(divided.first);
  if (motherFolder == folders.end()) // if the mother folder doesn't exist
    return false;
  motherFolder->second.subfolders.insert(fullPath);
  folders[fullPath];
  return true;
}
<commit_msg>Adding comment<commit_after>/*
 * FileSystem.cpp
 *
 *  Created on: Jun 20, 2014
 *      Author: Pimenta
 */

// this
#include "FileSystem.hpp"

using namespace std;
using namespace helpers;

map<string, FileSystem::Folder> FileSystem::folders;

void FileSystem::init() {
  folders.clear();
  folders["root"];
}

bool FileSystem::parseName(const string& name) {
  static set<char> allowedChars;
  static StaticInitializer staticInitializar([&]() {
    for (char c = '0'; c <= '9'; c++)
      allowedChars.insert(c);
    for (char c = 'a'; c <= 'z'; c++)
      allowedChars.insert(c);
    for (char c = 'A'; c <= 'Z'; c++)
      allowedChars.insert(c);
    allowedChars.insert('_');
    allowedChars.insert('-');
    allowedChars.insert('+');
    allowedChars.insert('.');
  });
  if (!name.size())
    return false;
  for (int i = 0; i < int(name.size()); i++) {
    if (allowedChars.find(name[i]) != allowedChars.end())
      return false;
  }
  return true;
}

bool FileSystem::parsePath(const string& path) {
  if (!path.size())
    return false;
  list<string> atoms = explode(path, '/');
  string tmp;
  auto it = atoms.begin();
  for (int i = 0; i < int(atoms.size()) - 1; i++) {
    if (!parseName(*it))
      return false;
    tmp += (*it);
    tmp += '/';
    it++;
  }
  if (it != atoms.end()) {
    if (!parseName(*it))
      return false;
    tmp += (*it);
  }
  return tmp == path;
}

bool FileSystem::createFolder(const string& fullPath) {//FIXME sync
  if (!parsePath(fullPath)) // if the path is invalid
    return false;
  if (folders.find(fullPath) != folders.end()) // if the folder already exists
    return false;
  pair<string, string> divided = divide(fullPath, '/');
  auto motherFolder = folders.find(divided.first);
  if (motherFolder == folders.end()) // if the mother folder doesn't exist
    return false;
  motherFolder->second.subfolders.insert(fullPath);
  folders[fullPath];
  return true;
}

{'fraction_non_alphanumeric': 0.1777430284076101, 'fraction_numerical': 0.005733646077664843, 'mean_word_length': 3.288268156424581, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '306742', 'n_tokens_mistral': 1329, 'n_tokens_neox': 1281, 'n_words': 343}