<commit_before>package com.googlecode.goclipse.debug.gdb;

import java.io.IOException;
import java.io.PushbackReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * 
 * @author devoncarew
 */
public class GdbProperties {
	protected String name;
	protected Map<String, Object> properties = new HashMap<String, Object>();
	
	public GdbProperties() {
		
	}
	
	public GdbProperties(String name) {
		this.name = name;
	}
	
	public String getName() {
		return name;
	}
	
	public Object getProperty(String key) {
		return properties.get(key);
	}
	
	public String getPropertyString(String key) {
		return (String)getProperty(key);
	}

	public Set<String> getKeys() {
		return properties.keySet();
	}
	
	@Override
  public String toString() {
	  return getName() + "=" + properties;
	}
	
	void parseKeyValues(PushbackReader in) throws IOException {
		while (true) {
			parseKeyValue(in);
			
			int ch = in.read();
			
			if (ch != ',') {
				if (ch != -1) {
					in.unread(ch);
				}
				
				return;
			}
		}
	}
	
	void parseKeyValue(PushbackReader in) throws IOException {
		String name = parseName(in);
		
		int ch = in.read();
		
		if (ch != '=') {
			throw new IOException("unexpected char: " + (char)ch);
		}
		
		Object value = parseValue(in);
		
		if (value instanceof GdbProperties) {
			GdbProperties props = (GdbProperties)value;
			
			props.name = name;
		}
		
		properties.put(name, value);
	}

	String parseName(PushbackReader in) throws IOException {
		StringBuilder builder = new StringBuilder();
		
		int ch = in.read();
		
		while (ch != '=' && ch != -1) {
			builder.append((char)ch);
			
			ch = in.read();
		}
		
		if (ch != -1) {
			in.unread(ch);
		}
		
		return builder.toString();
	}

	Object parseValue(PushbackReader in) throws IOException {
		int ch = in.read();
		
		switch (ch) {
		case '"':
			return parseStringValue(in);
		case '{':
			return parsePropertiesValue(in);
		case '[':
			return parseArrayValue(in);
		default:
			throw new IOException("unexpected char: " + (char)ch);
		}
	}

	String parseStringValue(PushbackReader in) throws IOException {
		StringBuilder builder = new StringBuilder();
		
		int lb = ' ';
		int ch = in.read();
				
		while ((lb=='\\' && ch == '"') || ch != '"' && ch != -1) {
			builder.append((char)ch);
			lb = ch;
			ch = in.read();
		}
		
		return builder.toString();
	}

	GdbProperties parsePropertiesValue(PushbackReader in) throws IOException {
		GdbProperties props = new GdbProperties();
		
		props.parseKeyValues(in);
		
		int ch = in.read();
		
		if (ch != '}') {
			throw new IOException("unexpected char: " + (char)ch);
		}
		
		return props;
	}

	Object[] parseArrayValue(PushbackReader in) throws IOException {
		// [object,oject,object]
		// {, or alphanum, or ]
		
		List<Object> objects = new ArrayList<Object>();
		
		while (true) {
			int ch = in.read();
			
			if (ch == ']') {
				return objects.toArray();
			} else if (ch == '{') {
				objects.add(parsePropertiesValue(in));
			} else {
				in.unread(ch);
				GdbProperties props = new GdbProperties();
				props.parseKeyValue(in);
				objects.add(props);
			}
			
			ch = in.read();
			
			if (ch == ']') {
				return objects.toArray();
			} else if (ch != ',') {
				throw new IOException("unexpected char: " + (char)ch);
			}
		}
	}<commit_msg>bugfix: error parsing gdb output with array elements of type string<commit_after>package com.googlecode.goclipse.debug.gdb;

import java.io.IOException;
import java.io.PushbackReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * 
 * @author devoncarew
 */
public class GdbProperties {
	protected String name;
	protected Map<String, Object> properties = new HashMap<String, Object>();
	
	public GdbProperties() {
		
	}
	
	public GdbProperties(String name) {
		this.name = name;
	}
	
	public String getName() {
		return name;
	}
	
	public Object getProperty(String key) {
		return properties.get(key);
	}
	
	public String getPropertyString(String key) {
		return (String)getProperty(key);
	}

	public Set<String> getKeys() {
		return properties.keySet();
	}
	
	@Override
  public String toString() {
	  return getName() + "=" + properties;
	}
	
	void parseKeyValues(PushbackReader in) throws IOException {
		while (true) {
			parseKeyValue(in);
			
			int ch = in.read();
			
			if (ch != ',') {
				if (ch != -1) {
					in.unread(ch);
				}
				
				return;
			}
		}
	}
	
	void parseKeyValue(PushbackReader in) throws IOException {
		String name = parseName(in);
		
		int ch = in.read();
		
		if (ch != '=') {
			throw new IOException("unexpected char: " + (char)ch);
		}
		
		Object value = parseValue(in);
		
		if (value instanceof GdbProperties) {
			GdbProperties props = (GdbProperties)value;
			
			props.name = name;
		}
		
		properties.put(name, value);
	}

	String parseName(PushbackReader in) throws IOException {
		StringBuilder builder = new StringBuilder();
		
		int ch = in.read();
		
		while (ch != '=' && ch != -1) {
			builder.append((char)ch);
			
			ch = in.read();
		}
		
		if (ch != -1) {
			in.unread(ch);
		}
		
		return builder.toString();
	}

	Object parseValue(PushbackReader in) throws IOException {
		int ch = in.read();
		
		switch (ch) {
		case '"':
			return parseStringValue(in);
		case '{':
			return parsePropertiesValue(in);
		case '[':
			return parseArrayValue(in);
		default:
			throw new IOException("unexpected char: " + (char)ch);
		}
	}

	String parseStringValue(PushbackReader in) throws IOException {
		StringBuilder builder = new StringBuilder();
		
		int lb = ' ';
		int ch = in.read();
				
		while ((lb=='\\' && ch == '"') || ch != '"' && ch != -1) {
			builder.append((char)ch);
			lb = ch;
			ch = in.read();
		}
		
		return builder.toString();
	}

	GdbProperties parsePropertiesValue(PushbackReader in) throws IOException {
		GdbProperties props = new GdbProperties();
		
		props.parseKeyValues(in);
		
		int ch = in.read();
		
		if (ch != '}') {
			throw new IOException("unexpected char: " + (char)ch);
		}
		
		return props;
	}

	Object[] parseArrayValue(PushbackReader in) throws IOException {
		// [object,oject,object]
		// {, or alphanum, or ]
		
		List<Object> objects = new ArrayList<Object>();
		
		while (true) {
			int ch = in.read();
			
			if (ch == ']') {
				return objects.toArray();
			} else if (ch == '{') {
				objects.add(parsePropertiesValue(in));
			} else if (ch == '"') {
				objects.add(parseStringValue(in));
			} else {
				in.unread(ch);
				GdbProperties props = new GdbProperties();
				props.parseKeyValue(in);
				objects.add(props);
			}
			
			ch = in.read();
			
			if (ch == ']') {
				return objects.toArray();
			} else if (ch != ',') {
				throw new IOException("unexpected char: " + (char)ch);
			}
		}
	}
{'fraction_non_alphanumeric': 0.15083308973984216, 'fraction_numerical': 0.001169248757673195, 'mean_word_length': 3.0229276895943564, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, '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': '5400082', 'n_tokens_mistral': 2735, 'n_tokens_neox': 2237, 'n_words': 542}