<commit_before>/**
* Copyright IBM Corporation 2016
*
* 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.
**/

import Foundation
import LoggerAPI

public struct StringUtils {

  /**
   Strips out any Url encoded whitespace and replaces it with a human readable space
   
   - parameter str: String to parse
   
   - returns: decoded string without whitespace encodings
   */
  static func decodeWhiteSpace(inString str: String) -> String {
    let decodedStr = str.replacingOccurrences(of: "%20", with: " ")
    Log.verbose("Decoded (whitespace) in string: '\(str)' to '\(decodedStr)'.")
    return decodedStr
  }

  /**
   Generates timestamp in specific format
   
   - returns: timestamp in String form
   */
  static func currentTimestamp() -> String {
    let dateStr = Date().description
    let ts = dateStr.substring(r: Range(0..<10)) + "T" + dateStr.substring(r: Range(11..<18))
    Log.verbose("Current time string: \(dateStr)")
    Log.verbose("Current timestamp generated: \(ts)")
    return ts
  }
}

public extension String {
    
    func substring(r: Range<Int>) -> String {
        let fromIndex = self.index(self.startIndex, offsetBy: r.lowerBound)
        let toIndex = self.index(self.startIndex, offsetBy: r.upperBound)
        return self.substring(with: Range<String.Index>(uncheckedBounds: (lower: fromIndex, upper: toIndex)))
    }
    
}<commit_msg>refactored currentTimestamp method to use date formatter instead of substring methods.<commit_after>/**
* Copyright IBM Corporation 2016
*
* 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.
**/

import Foundation
import LoggerAPI

public struct StringUtils {

  /**
   Strips out any Url encoded whitespace and replaces it with a human readable space
   
   - parameter str: String to parse
   
   - returns: decoded string without whitespace encodings
   */
  static func decodeWhiteSpace(inString str: String) -> String {
    let decodedStr = str.replacingOccurrences(of: "%20", with: " ")
    Log.verbose("Decoded (whitespace) in string: '\(str)' to '\(decodedStr)'.")
    return decodedStr
  }

  /**
   Generates timestamp in specific format
   
   - returns: timestamp in String form
   */
  static func currentTimestamp() -> String {
    let dateFormatter = DateFormatter()
    dateFormatter.locale = Locale(identifier: "en_US_POSIX")
    dateFormatter.timeZone = TimeZone(abbreviation: "GMT")
    dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss"
    let ts = dateFormatter.string(from: Date())
    Log.verbose("Current timestamp generated: \(ts)")
    return ts
  }
}
{'fraction_non_alphanumeric': 0.09832813828279965, 'fraction_numerical': 0.0076508926041371494, 'mean_word_length': 3.7066666666666666, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3946526', 'n_tokens_mistral': 1001, 'n_tokens_neox': 965, 'n_words': 373}