All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hypertino.inflector.naming.SnakeCaseParser.scala Maven / Gradle / Ivy

package com.hypertino.inflector.naming

object SnakeCaseParser extends IdentifierParser {
  override def parse(identifier: String, builder: IdentifierBuilder): Unit = {
    var prevIsUnderscore = false
    var underscoreConsumed = false
    for (c <- identifier) {
      if (prevIsUnderscore) {
        builder.divider()
        builder.regular(c)
        underscoreConsumed = true
        prevIsUnderscore = false
      }
      else {
        if (c == '_') {
          prevIsUnderscore = true
          underscoreConsumed = false
        } else {
          builder.regular(c)
          prevIsUnderscore = false
        }
      }
    }
    if (prevIsUnderscore && !underscoreConsumed) {
      builder.regular('_')
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy