<commit_before>#ifndef _IV_LV5_JSSTRINGOBJECT_H_
#define _IV_LV5_JSSTRINGOBJECT_H_
#include "lv5/jsobject.h"
#include "lv5/jsstring.h"
#include "lv5/context_utils.h"
#include "lv5/symbol_checker.h"
namespace iv {
namespace lv5 {

class JSStringObject : public JSObject {
 public:
  JSStringObject(Context* ctx, JSString* value)
    : value_(value) {
    DefineOwnProperty(
        ctx, context::length_symbol(ctx),
        DataDescriptor(JSVal::UInt32(static_cast<uint32_t>(value->size())),
                       PropertyDescriptor::NONE),
        false, NULL);
  }

  PropertyDescriptor GetOwnProperty(Context* ctx, Symbol name) const {
    uint32_t index;
    if (core::ConvertToUInt32(context::GetSymbolString(ctx, name), &index)) {
      return JSStringObject::GetOwnPropertyWithIndex(ctx, index);
    }
    return JSObject::GetOwnProperty(ctx, name);
  }

  PropertyDescriptor GetOwnPropertyWithIndex(Context* ctx,
                                             uint32_t index) const {
    if (const SymbolChecker check = SymbolChecker(ctx, index)) {
      PropertyDescriptor desc = JSObject::GetOwnProperty(ctx, check.symbol());
      if (!desc.IsEmpty()) {
        return desc;
      }
    }
    const std::size_t len = value_->size();
    if (len <= index) {
      return JSUndefined;
    }
    return DataDescriptor(
        JSString::New(ctx,
                      value_->begin() + index,
                      value_->begin() + index + 1),
        PropertyDescriptor::ENUMERABLE);
  }

  void GetOwnPropertyNames(Context* ctx,
                           std::vector<Symbol>* vec,
                           EnumerationMode mode) const {
    if (vec->empty()) {
      for (uint32_t i = 0, len = value_->size(); i < len; ++i) {
        vec->push_back(context::Intern(ctx, i));
      }
    } else {
      for (uint32_t i = 0, len = value_->size(); i < len; ++i) {
        const Symbol sym = context::Intern(ctx, i);
        if (std::find(vec->begin(), vec->end(), sym) == vec->end()) {
          vec->push_back(sym);
        }
      }
    }
    JSObject::GetOwnPropertyNames(ctx, vec, mode);
  }

  JSString* value() const {
    return value_;
  }

  static JSStringObject* New(Context* ctx, JSString* str) {
    JSStringObject* const obj = new JSStringObject(ctx, str);
    const Symbol name = context::Intern(ctx, "String");
    obj->set_cls(JSStringObject::GetClass());
    obj->set_prototype(context::GetClassSlot(ctx, Class::String).prototype);
    return obj;
  }

  static JSStringObject* NewPlain(Context* ctx) {
    return new JSStringObject(ctx, JSString::NewEmptyString(ctx));
  }

  static const Class* GetClass() {
    static const Class cls = {
      "String",
      Class::String
    };
    return &cls;
  }

 private:
  JSString* value_;<commit_msg>fix in compiling with clang<commit_after>#ifndef _IV_LV5_JSSTRINGOBJECT_H_
#define _IV_LV5_JSSTRINGOBJECT_H_
#include "lv5/jsobject.h"
#include "lv5/jsstring.h"
#include "lv5/context_utils.h"
#include "lv5/symbol_checker.h"
namespace iv {
namespace lv5 {

class JSStringObject : public JSObject {
 public:
  JSStringObject(Context* ctx, JSString* value)
    : value_(value) {
    DefineOwnProperty(
        ctx, context::length_symbol(ctx),
        DataDescriptor(JSVal::UInt32(static_cast<uint32_t>(value->size())),
                       PropertyDescriptor::NONE),
        false, NULL);
  }

  PropertyDescriptor GetOwnProperty(Context* ctx, Symbol name) const {
    uint32_t index;
    if (core::ConvertToUInt32(context::GetSymbolString(ctx, name), &index)) {
      return JSStringObject::GetOwnPropertyWithIndex(ctx, index);
    }
    return JSObject::GetOwnProperty(ctx, name);
  }

  PropertyDescriptor GetOwnPropertyWithIndex(Context* ctx,
                                             uint32_t index) const {
    if (const SymbolChecker check = SymbolChecker(ctx, index)) {
      PropertyDescriptor desc = JSObject::GetOwnProperty(ctx, check.symbol());
      if (!desc.IsEmpty()) {
        return desc;
      }
    }
    const std::size_t len = value_->size();
    if (len <= index) {
      return JSUndefined;
    }
    return DataDescriptor(
        JSString::New(ctx,
                      value_->begin() + index,
                      value_->begin() + index + 1),
        PropertyDescriptor::ENUMERABLE);
  }

  void GetOwnPropertyNames(Context* ctx,
                           std::vector<Symbol>* vec,
                           EnumerationMode mode) const {
    if (vec->empty()) {
      for (uint32_t i = 0, len = value_->size(); i < len; ++i) {
        vec->push_back(context::Intern(ctx, i));
      }
    } else {
      for (uint32_t i = 0, len = value_->size(); i < len; ++i) {
        const Symbol sym = context::Intern(ctx, i);
        if (std::find(vec->begin(), vec->end(), sym) == vec->end()) {
          vec->push_back(sym);
        }
      }
    }
    JSObject::GetOwnPropertyNames(ctx, vec, mode);
  }

  JSString* value() const {
    return value_;
  }

  static JSStringObject* New(Context* ctx, JSString* str) {
    JSStringObject* const obj = new JSStringObject(ctx, str);
    obj->set_cls(JSStringObject::GetClass());
    obj->set_prototype(context::GetClassSlot(ctx, Class::String).prototype);
    return obj;
  }

  static JSStringObject* NewPlain(Context* ctx) {
    return new JSStringObject(ctx, JSString::NewEmptyString(ctx));
  }

  static const Class* GetClass() {
    static const Class cls = {
      "String",
      Class::String
    };
    return &cls;
  }

 private:
  JSString* value_;
{'fraction_non_alphanumeric': 0.13099563953488372, 'fraction_numerical': 0.00872093023255814, 'mean_word_length': 2.7423521414004077, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6926377', 'n_tokens_mistral': 1702, 'n_tokens_neox': 1676, 'n_words': 366}