<commit_before>Promise = require('bluebird')
xml2js = Promise.promisifyAll(require('xml2js'))
Utils = require('./utils')
parser = new xml2js.Parser()

class SharedStringsTable

  @parse:(xml)->
    return new Promise (resolve, reject)->
      unless xml
        resolve(new SharedStringsTable)
        return
      parser.parseString xml,(err, result)->
        resolve(new SharedStringsTable(result))


  constructor:(xmlobj)->
    @_ = {}
    @_.count = 0
    @_.uniqueCount = 0
    @_.strings = []
    if xmlobj
      @_.count = xmlobj.sst.$.count
      @_.uniqueCount = xmlobj.sst.$.uniqueCount
      for si in xmlobj.sst.si
        str = si.t[0]
        if str._
          str = str._
        str += ""
        @_.strings.push str.replace(/\r/g, "")


  Object.defineProperties @prototype,
    "count":
      get: -> @_.count
    "uniqueCount":
      get: -> @_.uniqueCount

  get: (id)->
    @_.strings[id]

  add: (str)->
    idx = @_.strings.indexOf str<commit_msg>Add checks for empty SST<commit_after>Promise = require('bluebird')
xml2js = Promise.promisifyAll(require('xml2js'))
Utils = require('./utils')
parser = new xml2js.Parser()

class SharedStringsTable

  @parse:(xml)->
    return new Promise (resolve, reject)->
      unless xml
        resolve(new SharedStringsTable)
        return
      parser.parseString xml,(err, result)->
        resolve(new SharedStringsTable(result))


  constructor:(xmlobj)->
    @_ = {}
    @_.count = 0
    @_.uniqueCount = 0
    @_.strings = []
    if xmlobj && xmlobj.sst && xmlobj.sst.si
      @_.count = xmlobj.sst.$.count
      @_.uniqueCount = xmlobj.sst.$.uniqueCount
      for si in xmlobj.sst.si
        str = si.t[0]
        if str._
          str = str._
        str += ""
        @_.strings.push str.replace(/\r/g, "")


  Object.defineProperties @prototype,
    "count":
      get: -> @_.count
    "uniqueCount":
      get: -> @_.uniqueCount

  get: (id)->
    @_.strings[id]

  add: (str)->
    idx = @_.strings.indexOf str
{'fraction_non_alphanumeric': 0.15140845070422534, 'fraction_numerical': 0.006036217303822937, 'mean_word_length': 2.3039867109634553, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 24}, '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': '2207852', 'n_tokens_mistral': 660, 'n_tokens_neox': 631, 'n_words': 141}