<commit_before>//
//  Copyright (C) 2012 <NAME>
//
//  @@ All Rights Reserved @@
//  This file is part of the RDKit.
//  The contents are covered by the terms of the BSD license
//  which is included in the file license.txt, found at the root
//  of the RDKit source tree.
//
//
#ifndef _RD_LOCALESWITCHER_H
#define _RD_LOCALESWITCHER_H

#include <clocale>
#ifndef _MSC_VER
# include <xlocale.h>
#else
# include <locale.h>
#endif

namespace RDKit {
namespace Utils {
// allows an RAII-like approach to ensuring the locale is temporarily "C"
// instead of whatever we started in.
class LocaleSwitcher {
 public:
#ifdef _MSC_VER  

  LocaleSwitcher() {
#ifdef RDK_THREADSAFE_SSS
    _configthreadlocale(_ENABLE_PER_THREAD_LOCALE);
    ::setlocale(LC_ALL, "C");
#else    
    std::setlocale(LC_ALL, "C");
#endif
  }
  ~LocaleSwitcher() {
#ifdef RDK_THREADSAFE_SSS
    ::setlocale(LC_ALL, "C");
#else    
    std::setlocale(LC_ALL, "");
#endif
  }
#else

LocaleSwitcher() : old_locale(setlocale(LC_ALL, NULL)) {
    // set locale for this thread

    if (!Recurse() && old_locale != "C") {
      Recurse(1);
      locale_t loc = newlocale(LC_ALL_MASK, "C", (locale_t)0);
      uselocale(loc);
      // Don't free "C" or "GLOBAL" Locales
    } else
      old_locale = "C";
  }
  ~LocaleSwitcher() {
    if (old_locale != "C") {
      locale_t loc = newlocale(LC_ALL_MASK, old_locale.c_str(), (locale_t)0);
      uselocale(loc);
      // Don't free "C" or "GLOBAL" Locales
      Recurse(-1);
    }
  }
  // Recurse(1) recurse into switcher
  // Recurse(-1) end recursion
  //  Always turns current state (note: thread safe
  //   when RDK_THREAFSAFE_SSS defined)
  static int Recurse(int state=0);
  
public:
  std::string old_locale;

#endif
  
};
}
}

#endif<commit_msg>Add WINDOWS recursion support<commit_after>//
//  Copyright (C) 2012 <NAME>
//
//  @@ All Rights Reserved @@
//  This file is part of the RDKit.
//  The contents are covered by the terms of the BSD license
//  which is included in the file license.txt, found at the root
//  of the RDKit source tree.
//
//
#ifndef _RD_LOCALESWITCHER_H
#define _RD_LOCALESWITCHER_H

#include <clocale>
#ifndef _MSC_VER
# include <xlocale.h>
#else
# include <locale.h>
#endif

namespace RDKit {
namespace Utils {
// allows an RAII-like approach to ensuring the locale is temporarily "C"
// instead of whatever we started in.
class LocaleSwitcher {
 public:
#ifdef _MSC_VER  

  LocaleSwitcher() {
    if (!Recurse()) {
#ifdef RDK_THREADSAFE_SSS
    _configthreadlocale(_ENABLE_PER_THREAD_LOCALE);
    ::setlocale(LC_ALL, "C");
#else    
    std::setlocale(LC_ALL, "C");
#endif
    Recurse(1);
    switched = true;
    }
  }
  ~LocaleSwitcher() {
    if (switched) {
#ifdef RDK_THREADSAFE_SSS
    ::setlocale(LC_ALL, "C");
#else    
    std::setlocale(LC_ALL, "");
#endif
    Recurse(-1);
    }
  }
public:
  bool switched;
#else

LocaleSwitcher() : old_locale(setlocale(LC_ALL, NULL)) {
    // set locale for this thread

    if (!Recurse() && old_locale != "C") {
      Recurse(1);
      locale_t loc = newlocale(LC_ALL_MASK, "C", (locale_t)0);
      uselocale(loc);
      // Don't free "C" or "GLOBAL" Locales
    } else
      old_locale = "C";
  }
  ~LocaleSwitcher() {
    if (old_locale != "C") {
      locale_t loc = newlocale(LC_ALL_MASK, old_locale.c_str(), (locale_t)0);
      uselocale(loc);
      // Don't free "C" or "GLOBAL" Locales
      Recurse(-1);
    }
  }
  
public:
  std::string old_locale;

#endif

  // Recurse(1) recurse into switcher
  // Recurse(-1) end recursion
  //  Always turns current state (note: thread safe
  //   when RDK_THREAFSAFE_SSS defined)
  static int Recurse(int state=0);
  
};
}
}

#endif
{'fraction_non_alphanumeric': 0.133623030961434, 'fraction_numerical': 0.006518196632265073, 'mean_word_length': 3.1289237668161434, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '2466109', 'n_tokens_mistral': 1399, 'n_tokens_neox': 1352, 'n_words': 357}