@@ -8,7 +8,6 @@ namespace UnityEditor.XCodeEditor
88{
99 public class PBXParser
1010 {
11-
1211 public const char WHITESPACE_SPACE = ' ' ;
1312 public const char WHITESPACE_TAB = '\t ' ;
1413 public const char WHITESPACE_NEWLINE = '\n ' ;
@@ -23,20 +22,6 @@ public class PBXParser
2322 public const char QUOTEDSTRING_BEGIN_TOKEN = '"' ;
2423 public const char QUOTEDSTRING_END_TOKEN = '"' ;
2524 public const char QUOTEDSTRING_ESCAPE_TOKEN = '\\ ' ;
26- public const char DATA_BEGIN_TOKEN = '<' ;
27- public const char DATA_END_TOKEN = '>' ;
28- public const char DATA_GSOBJECT_BEGIN_TOKEN = '*' ;
29- public const char DATA_GSDATE_BEGIN_TOKEN = 'D' ;
30- public const char DATA_GSBOOL_BEGIN_TOKEN = 'B' ;
31- public const char DATA_GSBOOL_TRUE_TOKEN = 'Y' ;
32- public const char DATA_GSBOOL_FALSE_TOKEN = 'N' ;
33- public const char DATA_GSINT_BEGIN_TOKEN = 'I' ;
34- public const char DATA_GSREAL_BEGIN_TOKEN = 'R' ;
35- public const char DATE_DATE_FIELD_DELIMITER = '-' ;
36- public const char DATE_TIME_FIELD_DELIMITER = ':' ;
37- public const char DATE_GS_DATE_TIME_DELIMITER = ' ' ;
38- public const char DATE_APPLE_DATE_TIME_DELIMITER = 'T' ;
39- public const char DATE_APPLE_END_TOKEN = 'Z' ;
4025 public const char END_OF_FILE = ( char ) 0x1A ;
4126 public const string COMMENT_BEGIN_TOKEN = "/*" ;
4227 public const string COMMENT_END_TOKEN = "*/" ;
@@ -46,7 +31,6 @@ public class PBXParser
4631 private char [ ] data ;
4732 private int index ;
4833// private bool success;
49- private int indent = 0 ;
5034
5135 public object Decode ( string data )
5236 {
@@ -57,83 +41,10 @@ public object Decode( string data )
5741 }
5842
5943 data = data . Substring ( 13 ) ;
60- // char[] charToTrim = { WHITESPACE_TAB, WHITESPACE_NEWLINE, WHITESPACE_CARRIAGE_RETURN };
61- // data = data.Trim( charToTrim );
62-
6344 this . data = data . ToCharArray ( ) ;
64- Debug . Log ( this . data ) ;
6545 return Parse ( ) ;
66- //return null;
6746 }
68-
69-
7047
71-
72- // ALTRO METODO
73- // #region Read
74- //
75- // private bool Accept( char[] acceptableSymbols )
76- // {
77- // bool symbolPresent = false;
78- // foreach( char c in acceptableSymbols ) {
79- // if( data[index] == c )
80- // symbolPresent = true;
81- // }
82- // return symbolPresent;
83- // }
84- //
85- // private bool Accept( char acceptableSymbol )
86- // {
87- // return data[index] == acceptableSymbol;
88- // }
89- //
90- // private void Expect( char[] expectedSymbols )
91- // {
92- // if( !Accept( expectedSymbols ) ) {
93- // string excString = "Expected " + expectedSymbols[0] + "'";
94- // foreach( char c in expectedSymbols )
95- // excString += "'" + c + "' ";
96- //
97- // excString += " but found '" + (char)data[index] + "' at index " + index;
98- // throw new System.Exception( excString );
99- // }
100- // }
101- //
102- // private void Expect( char expectedSymbol )
103- // {
104- // if( !Accept( expectedSymbol ) )
105- // throw new System.Exception( "Expected '" + expectedSymbol + "' but found '" + (char)data[index] + "' at index " + index );
106- // }
107- //
108- // private void Read( char symbol )
109- // {
110- // Expect( symbol );
111- // index++;
112- // }
113- //
114- // private string ReadInputUntil( char[] symbols )
115- // {
116- // string s = string.Empty;
117- // while( !Accept( symbols ) ) {
118- // s += (char)data[index];
119- // Skip();
120- // }
121- // index--;
122- // return s;
123- // }
124- //
125- // private string ReadInputUntil( char symbol )
126- // {
127- // string s = string.Empty;
128- // while( !Accept( symbol ) ) {
129- // s += (char)data[index];
130- // Skip();
131- // }
132- // index--;
133- // return s;
134- // }
135- //
136- // #endregion
13748 #region Move
13849
13950 private char NextToken ( )
@@ -163,8 +74,6 @@ private string Peek( int step = 1 )
16374
16475 private bool SkipWhitespaces ( )
16576 {
166- // Debug.Log( "Skip whitespace start: " + index );
167-
16877 bool whitespace = false ;
16978 while ( Regex . IsMatch ( StepForeward ( ) . ToString ( ) , @"\s" ) )
17079 whitespace = true ;
@@ -196,8 +105,6 @@ private bool SkipWhitespaces()
196105
197106 private bool SkipComments ( )
198107 {
199- // Debug.Log( "Skip comment" );
200-
201108 string s = string . Empty ;
202109 string tag = Peek ( 2 ) ;
203110 switch ( tag ) {
@@ -206,7 +113,7 @@ private bool SkipComments()
206113 s += StepForeward ( ) ;
207114 }
208115 s += StepForeward ( 2 ) ;
209- Debug . Log ( "Skipped comment: \" " + s + "\" " ) ;
116+ // Debug.Log( "Skipped comment: \"" + s + "\"" );
210117 break ;
211118 }
212119 case COMMENT_LINE_TOKEN : {
@@ -274,8 +181,6 @@ public object Parse()
274181
275182 private object ParseValue ( )
276183 {
277- Debug . Log ( "Parse value" ) ;
278-
279184 switch ( NextToken ( ) ) {
280185 case END_OF_FILE :
281186 Debug . Log ( "End of file" ) ;
@@ -310,131 +215,51 @@ private object ParseValue()
310215// return self.parse_entity()
311216 }
312217
313- // private object ParseObject()
314- // {
315- // Debug.Log( "Parse object" );
316- // switch( NextToken() ) {
317- // case ARRAY_BEGIN_TOKEN: {
318- // return ParseArray();
319- // }
320- // case DICTIONARY_BEGIN_TOKEN: {
321- // return ParseDictionary();
322- // }
323- //// case DATA_BEGIN_TOKEN : {
324- //// return ParseData();
325- //// }
326- //// case QUOTEDSTRING_BEGIN_TOKEN : {
327- //// String quotedString = parseQuotedString();
328- //// //apple dates are quoted strings of length 20 and after the 4 year digits a dash is found
329- //// if(quotedString.length()==20 && quotedString.charAt(4)==DATE_DATE_FIELD_DELIMITER) {
330- //// try {
331- //// NSDate date = new NSDate(quotedString);
332- //// return date;
333- //// } catch(Exception ex) {
334- //// //not a date? --> return string
335- //// return new NSString(quotedString);
336- //// }
337- //// } else {
338- //// return new NSString(quotedString);
339- //// }
340- //// }
341- // default : {
342- // Debug.Log( "default" );
343- // return ParseEntity();
344- //
345- // //0-9
346- //// if( data[index] > 0x2F && data[index] < 0x3A ) {
347- //// //int, real or date
348- //// return ParseNumerical();
349- //// } else {
350- //// //non-numerical -> string or boolean
351- //// return ParseString();
352- //
353- //// string parsedString = ParseString();
354- ////
355- //// if( parsedString.Equals( "YES" ) ) {
356- //// return new NSNumber(true);
357- //// } else if(parsedString.equals("NO")) {
358- //// return new NSNumber(false);
359- //// } else {
360- //// return new NSString(parsedString);
361- //// }
362- //// }
363- // }
364- // }
365- // }
366-
367218 private object ParseDictionary ( )
368219 {
369- Debug . Log ( "Parse dictionary" ) ;
370-
371220 SkipWhitespaces ( ) ;
372221 Hashtable dictionary = new Hashtable ( ) ;
373222 string keyString = string . Empty ;
374223 object valueObject = null ;
375- // KeyValuePair<string, object> entry = new KeyValuePair<string, object>();
376-
377- // indent += 1;
378- // Debug.Log( "iniziato " + indent );
224+
379225 bool complete = false ;
380226 while ( ! complete ) {
381-
382227 switch ( NextToken ( ) ) {
383228 case END_OF_FILE :
384229 Debug . Log ( "Error: reached end of file inside a dictionary: " + index ) ;
230+ complete = true ;
385231 break ;
386232
387- case DICTIONARY_ASSIGN_TOKEN : {
388- Debug . Log ( "Parse dictionary assign: " + keyString + " - " + valueObject ) ;
389- if ( string . IsNullOrEmpty ( keyString ) ) {
390- throw new System . Exception ( "Unexpected " + DICTIONARY_ASSIGN_TOKEN + " token. Expected ke before assign token." ) ;
391- } else
392- if ( valueObject != null ) {
393- throw new System . Exception ( "An object is already set for key " + keyString + "." ) ;
394- }
395- Debug . Log ( "completa?" ) ;
396- break ;
397- }
398- case DICTIONARY_ITEM_DELIMITER_TOKEN : {
399- Debug . Log ( "Parse dictionary delimeter" ) ;
400- if ( string . IsNullOrEmpty ( keyString ) ) {
401- throw new System . Exception ( "Missing key before assign token." ) ;
402- }
403- dictionary . Add ( keyString , valueObject ) ;
404- // keyString = string.Empty;
405- // valueObject = null;
233+ case DICTIONARY_ITEM_DELIMITER_TOKEN :
234+ // if( string.IsNullOrEmpty( keyString ) ) {
235+ // throw new System.Exception( "Missing key before assign token." );
236+ // }
237+
238+ keyString = string . Empty ;
239+ valueObject = null ;
406240 break ;
407- }
408- case DICTIONARY_END_TOKEN : {
409- Debug . Log ( "Parse dictionary end" ) ;
410- if ( ! string . IsNullOrEmpty ( keyString ) && valueObject != null ) {
411- dictionary . Add ( keyString , valueObject ) ;
412- // keyString = string.Empty;
413- // valueObject = null;
414- }
415241
416- Debug . Log ( "Chiuso " + indent ) ;
417- indent -= 1 ;
242+ case DICTIONARY_END_TOKEN :
243+ // if( !string.IsNullOrEmpty( keyString ) && valueObject != null ) {
244+ //
245+ // }
246+
247+ keyString = string . Empty ;
248+ valueObject = null ;
418249 complete = true ;
419250 break ;
420- }
421- default : {
422- Debug . Log ( "Parse dictionary default" ) ;
251+
252+ case DICTIONARY_ASSIGN_TOKEN :
253+ valueObject = ParseValue ( ) ;
254+ dictionary . Add ( keyString , valueObject ) ;
255+ break ;
256+
257+ default :
423258 StepBackward ( ) ;
424- if ( string . IsNullOrEmpty ( keyString ) ) {
425- keyString = ParseValue ( ) as string ;
426- } else {
427- valueObject = ParseValue ( ) ;
428- if ( valueObject == null )
429- Debug . Log ( "VALUE: Qualcosa non va!" ) ;
430- else
431- Debug . Log ( "VALUE: " + valueObject . ToString ( ) ) ;
432- }
259+ keyString = ParseValue ( ) as string ;
433260 break ;
434- }
435261 }
436262 }
437- Debug . Log ( "Parse dictionary completo" ) ;
438263 return dictionary ;
439264
440265// def parse_dictionary(self):
@@ -469,8 +294,6 @@ private object ParseDictionary()
469294
470295 private ArrayList ParseArray ( )
471296 {
472- Debug . Log ( "Parse array" ) ;
473-
474297 ArrayList list = new ArrayList ( ) ;
475298 bool complete = false ;
476299 while ( ! complete ) {
@@ -512,8 +335,6 @@ private ArrayList ParseArray()
512335
513336 private object ParseString ( )
514337 {
515- Debug . Log ( "Parse string" ) ;
516-
517338 string s = string . Empty ;
518339 char c = StepForeward ( ) ;
519340 while ( c != QUOTEDSTRING_END_TOKEN ) {
@@ -524,8 +345,6 @@ private object ParseString()
524345
525346 c = StepForeward ( ) ;
526347 }
527-
528- Debug . Log ( s ) ;
529348 return s ;
530349
531350// def parse_string(self):
@@ -545,8 +364,6 @@ private object ParseString()
545364
546365 private object ParseEntity ( )
547366 {
548- Debug . Log ( "Parse entity" ) ;
549-
550367 string word = string . Empty ;
551368 char c = StepForeward ( ) ;
552369
@@ -555,12 +372,9 @@ private object ParseEntity()
555372 c = StepForeward ( ) ;
556373 }
557374
558- if ( word . Length != 24 && Regex . IsMatch ( word , @"^\d+$" ) ) {
559- Debug . Log ( "Found number: " + word ) ;
375+ if ( word . Length != 24 && Regex . IsMatch ( word , @"^\d+$" ) )
560376 return Int32 . Parse ( word ) ;
561- }
562377
563- Debug . Log ( "Found word: " + word ) ;
564378 return word ;
565379
566380// def parse_entity(self):
@@ -581,10 +395,5 @@ private object ParseEntity()
581395
582396 #endregion
583397
584- public void test ( )
585- {
586- Debug . Log ( "TEST: " + index + ", " + data [ index ] + " - " + NextToken ( ) + ", " + index ) ;
587- }
588-
589398 }
590399}
0 commit comments