Gestion des champs "phrase" entre quotes
This commit is contained in:
parent
4beaf7ef8a
commit
3f48636636
|
@ -1,3 +1,4 @@
|
||||||
id name value
|
id name value
|
||||||
0 test0 testvalue0
|
0 test testvalue0
|
||||||
1 test1 testvalue1
|
1 test1 testvalue1
|
||||||
|
2 "Test Multiword" "Ddeedz fdes s fesq qs g sfddtrs"
|
|
@ -1,5 +1,6 @@
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using System.Collections;
|
using System.Collections.Generic;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
public class TwoDA : Object {
|
public class TwoDA : Object {
|
||||||
|
|
||||||
|
@ -12,22 +13,31 @@ public class TwoDA : Object {
|
||||||
m_header = line.Split();
|
m_header = line.Split();
|
||||||
int nCols = m_header.Length;
|
int nCols = m_header.Length;
|
||||||
|
|
||||||
m_data = new string[100, nCols-1];//TODO: make this array dynamic instead of 100
|
m_data = new List<string[]>();
|
||||||
|
|
||||||
int nFileLine = 1;
|
int nFileLine = 1;
|
||||||
while((line = file.ReadLine()) != null)
|
while((line = file.ReadLine()) != null)
|
||||||
{
|
{
|
||||||
if(line[0] != '#'){//Ignore commented lines
|
if(line[0] != '#'){//Ignore commented lines
|
||||||
string[] linedata = line.Split();
|
|
||||||
if(linedata.Length == nCols){
|
|
||||||
int nLine = int.Parse(linedata[0]);
|
|
||||||
|
|
||||||
|
MatchCollection matches = m_rgxField.Matches(line);
|
||||||
|
|
||||||
|
if(matches.Count == nCols){
|
||||||
|
int nLine = int.Parse(matches[0].Value);
|
||||||
|
|
||||||
|
string[] buff = new string[nCols-1];
|
||||||
for(int i=0 ; i<nCols-1 ; i++){
|
for(int i=0 ; i<nCols-1 ; i++){
|
||||||
m_data[nLine, i] = linedata[i+1];
|
|
||||||
|
if(matches[i+1].Groups[1].Success)//Match one word
|
||||||
|
buff[i] = matches[i+1].Groups[1].Value;
|
||||||
|
else if(matches[i+1].Groups[2].Success)//Match multi word
|
||||||
|
buff[i] = matches[i+1].Groups[2].Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_data.Add(buff);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
Debug.LogWarning(filepath+":"+nFileLine.ToString()+" ignored. Found "+linedata.Length.ToString()+" columns instead of "+nCols.ToString());
|
Debug.LogWarning(filepath+":"+nFileLine.ToString()+" ignored. Found "+matches.Count.ToString()+" columns instead of "+nCols.ToString());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,7 +51,7 @@ public class TwoDA : Object {
|
||||||
|
|
||||||
int nCol = FindHeaderCol(sColumn);
|
int nCol = FindHeaderCol(sColumn);
|
||||||
if(nCol>=0){
|
if(nCol>=0){
|
||||||
return m_data[nRow, nCol];
|
return m_data[nRow][nCol];
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
throw new UnityException("Column '"+sColumn+"' not found in 2DA");
|
throw new UnityException("Column '"+sColumn+"' not found in 2DA");
|
||||||
|
@ -55,10 +65,10 @@ public class TwoDA : Object {
|
||||||
sMsg += s+"\t";
|
sMsg += s+"\t";
|
||||||
}
|
}
|
||||||
sMsg += "\n";
|
sMsg += "\n";
|
||||||
for(int line=0 ; line<m_data.GetLength(0) ; line++){
|
for(int line=0 ; line<m_data.Count ; line++){
|
||||||
sMsg += line.ToString() + "\t";
|
sMsg += line.ToString() + "\t";
|
||||||
for(int col=0 ; col<m_data.GetLength(1) ; col++){
|
for(int col=0 ; col<m_data[line].Length ; col++){
|
||||||
sMsg += m_data[line, col]+"\t";
|
sMsg += m_data[line][col]+"\t";
|
||||||
}
|
}
|
||||||
sMsg += "\n";
|
sMsg += "\n";
|
||||||
}
|
}
|
||||||
|
@ -73,7 +83,7 @@ public class TwoDA : Object {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Regex m_rgxField = new Regex("(?:\\b([^\\s]+?)\\b|\"([^\"]+?)\")");
|
||||||
private string[] m_header;
|
private string[] m_header;
|
||||||
private string[,] m_data;
|
private List<string[]> m_data;
|
||||||
}
|
}
|
Loading…
Reference in New Issue