<commit_before>package de.zalando.apifirst

import scala.language.postfixOps

/**
 * @author  slasch 
 * @since   03.11.2015.
 */
object new_naming {

  type TypeName = Reference

  abstract class PointerNode {
    def asString: String
  }

  final case class Node(private val raw: String) extends PointerNode {
    override def asString = JsonPointer.escape(raw)
  }

  final case class Index(i: Long) extends PointerNode {
    assert(i >= 0, "index must be positive")

    override def asString = i.toString
  }

  final case class JsonPointer(values: Seq[PointerNode]) {
    def ++(that: JsonPointer): JsonPointer = {
      val append = if (that.values.headOption.exists(_ == Node(""))) that.values.tail else that.values
      JsonPointer(values ++ append)
    }

    def :+(node: PointerNode): JsonPointer = JsonPointer(values :+ node)

    def :+(nodeStr: String): JsonPointer = JsonPointer(values :+ Node(nodeStr))

    def +:(node: PointerNode): JsonPointer = JsonPointer(node +: values)

    def +:(nodeStr: String): JsonPointer = JsonPointer(Node(nodeStr) +: values)

    override def toString: String = values match {
      case Nil => ""
      case nonempty => nonempty.map(_.asString).mkString("#", "/", "")
    }

    private lazy val parentValues = values match {
      case Nil => Nil
      case _ => values.init
    }
    lazy val parent = JsonPointer(parentValues)
    lazy val simple = values.lastOption.map(_.asString).getOrElse("")
  }

  implicit object PointerNodeOrdering extends Ordering[PointerNode] {
    override def compare(x: PointerNode, y: PointerNode): Int = (x, y) match {
      case (Index(_), Node(_)) => -1
      case (Node(_), Index(_)) => 1
      case (Index(a), Index(b)) => a compare b
      case (Node(a), Node(b)) => a compare b
    }
  }

  object JsonPointer {

    def escape(str: String) = str.replace("~", "~0").replace("/", "~1")

    def unescape(str: String) = str.replace("~0", "~").replace("~1", "/")
<commit_msg>#14 As per specification [https://tools.ietf.org/html/rfc6901#page-3](evaluation order)<commit_after>package de.zalando.apifirst

import scala.language.postfixOps

/**
 * @author  slasch 
 * @since   03.11.2015.
 */
object new_naming {

  type TypeName = Reference

  abstract class PointerNode {
    def asString: String
  }

  final case class Node(private val raw: String) extends PointerNode {
    override def asString = JsonPointer.escape(raw)
  }

  final case class Index(i: Long) extends PointerNode {
    assert(i >= 0, "index must be positive")

    override def asString = i.toString
  }

  final case class JsonPointer(values: Seq[PointerNode]) {
    def ++(that: JsonPointer): JsonPointer = {
      val append = if (that.values.headOption.exists(_ == Node(""))) that.values.tail else that.values
      JsonPointer(values ++ append)
    }

    def :+(node: PointerNode): JsonPointer = JsonPointer(values :+ node)

    def :+(nodeStr: String): JsonPointer = JsonPointer(values :+ Node(nodeStr))

    def +:(node: PointerNode): JsonPointer = JsonPointer(node +: values)

    def +:(nodeStr: String): JsonPointer = JsonPointer(Node(nodeStr) +: values)

    override def toString: String = values match {
      case Nil => ""
      case nonempty => nonempty.map(_.asString).mkString("#", "/", "")
    }

    private lazy val parentValues = values match {
      case Nil => Nil
      case _ => values.init
    }
    lazy val parent = JsonPointer(parentValues)
    lazy val simple = values.lastOption.map(_.asString).getOrElse("")
  }

  implicit object PointerNodeOrdering extends Ordering[PointerNode] {
    override def compare(x: PointerNode, y: PointerNode): Int = (x, y) match {
      case (Index(_), Node(_)) => -1
      case (Node(_), Index(_)) => 1
      case (Index(a), Index(b)) => a compare b
      case (Node(a), Node(b)) => a compare b
    }
  }

  object JsonPointer {

    def escape(str: String) = str.replace("~", "~0").replace("/", "~1")

    def unescape(str: String) = str.replace("~1", "/").replace("~0", "~")

{'fraction_non_alphanumeric': 0.14485514485514486, 'fraction_numerical': 0.00924075924075924, 'mean_word_length': 3.3675027262813524, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, 'https://': 1, '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': '7317496', 'n_tokens_mistral': 1288, 'n_tokens_neox': 1224, 'n_words': 345}