Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parseRec substring index problem #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ireina7
Copy link

@ireina7 ireina7 commented Oct 27, 2020

Original Code in package.scala:

private def parseRec(s : String) : (Int,String,String) = if(s.isEmpty)  (0,s,s) else {
    s.head match {
      ...
      case 'L' => {
        val end = s.indexOf(';')
        if(end < 0) sys.error("Malformed type (sub)string: " + s)
        (1, s.substring(0, end), s.substring(end + 1, s.size))
      }
      ...
      case _ => sys.error("Malformed type (sub)string: " + s)
    }
  }

I think the original code case 'L' => {... (1, s.substring(0, end), ...) ...} should be be case 'L' => {... (1, s.substring(0, end + 1), ...) ...} since the parameter end in method substring is exclusive, therefore:

After

private def parseRec(s : String) : (Int,String,String) = if(s.isEmpty)  (0,s,s) else {
    s.head match {
      ...
      case 'L' => {
        val end = s.indexOf(';')
        if(end < 0) sys.error("Malformed type (sub)string: " + s)
        (1, s.substring(0, end + 1), s.substring(end + 1, s.size))
      }
      ...
      case _ => sys.error("Malformed type (sub)string: " + s)
    }
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants