We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Unterminated string constant error in 0186
Page Index Toggle Pages: 1
Unterminated string constant error in 0186 (Read 1428 times)
Unterminated string constant error in 0186
Mar 29th, 2010, 2:58pm
 
Hello!

I'm getting an "unterminated string constant" error whenever I run programs in Processing 0186. I'm guessing it has something to do with a parsing function I'm using that is grabbing my csv files and chopping them up. I found some mention of this error in other programming languages and so I'm guessing that new Processing doesn't like how the function I have is either chopping up lines or it straight up doesn't like files with multiple lines? That seems weird to me but I didn't write the parsing code so I'm not 100% sure how it works. Here's the code:

Quote:
void parse(String[] lines) {
  for (int i = 0; i < lines.length; i++) {
    String[] pieces = splitLine(lines[i]);
// this is where I put some other code that takes the pieces array and adds it to some other array list or hash map or something.
    
}
}

/*------------------------------------------------------------------------------
-----*/


String[] splitLine(String line) {
  char[] c = line.toCharArray(  );
  ArrayList pieces = new ArrayList(  );
  int prev = 0;
  boolean insideQuote = false;
  for (int i = 0; i < c.length; i++) {
    if (c[i] == ',') {
      if (!insideQuote) {
        // Whitespace must be trimmed between commas.
        String s = new String(c, prev, i - prev).trim(  );
        pieces.add(s);
        prev = i+1;
      }
    } 
    else if (c[i] == '\"') {
      insideQuote = !insideQuote;
    }
  }
  if (prev != c.length) {
    String s = new String(c, prev, c.length - prev).trim(  );
    pieces.add(s);
  }
  String[] outgoing = new String[pieces.size(  )];
  pieces.toArray(outgoing);
  scrubQuotes(outgoing);
  return outgoing;
}

/*------------------------------------------------------------------------------
-----*/


// Parse quotes from CSV data. Quotes around a column are common,
// and actual double quotes (") are specified by two double quotes ("").
void scrubQuotes(String[] array) {
  for (int i = 0; i < array.length; i++) {
    if (array[i].length(  ) > 2) {
      // Remove quotes at start and end, if present.
      if (array[i].startsWith("\"") && array[i].endsWith("\"")) {
        array[i] = array[i].substring(1, array[i].length(  ) - 1);
      }
    }
    // Make double quotes into single quotes.
    array[i] = array[i].replaceAll("\"\"", "\"");
  }
}




I took out my code that sends the pieces array to another array because I use this function on nearly every program I write but what I actually do with the data is different each time and I am getting the same error, even if there's nothing in there.

In the meantime, I went back to Processing 1.1 so I can keep working on my code but it'd be great to be able to output PDF files with text and I'll have to upgrade at some point.

Any thoughts?

thanks!
amy
Re: Unterminated string constant error in 0186
Reply #1 - Mar 30th, 2010, 2:45am
 
Where did you got this 0186 version?
On the download page, I see only the 0182 as last release. Perhaps they made the 0186 available for a brief time. If so, maybe they removed it because of bugs?
BTW, the official current version is 1.1 (0179), I think the versions above that are beta (experimental) and prone to changes/fixes.
Actually, I totally missed these new versions (no announcements), I see with joy that Java 1.5 syntax is supported, it will download it and test it! Yeay!

Back to your issue, well, it is safer to go back to 1.1, indeed, and wait for a stable version: such changes are prone to be fixed.
Re: Unterminated string constant error in 0186
Reply #2 - Mar 31st, 2010, 9:47am
 
Der. I meant 0182... I have been very, very tired lately. And for whatever reason I wasn't sure about the number system, so I will stick with 1.1. Thanks!!
Re: Unterminated string constant error in 0186
Reply #3 - Apr 6th, 2010, 11:36am
 
Page Index Toggle Pages: 1