Move some .drv parsing functions out of util
This commit is contained in:
		
							parent
							
								
									2c8c103ef8
								
							
						
					
					
						commit
						e07c0dcf5c
					
				
					 3 changed files with 46 additions and 55 deletions
				
			
		|  | @ -87,6 +87,38 @@ Path writeDerivation(ref<Store> store, | |||
| } | ||||
| 
 | ||||
| 
 | ||||
| MakeError(FormatError, Error) | ||||
| 
 | ||||
| 
 | ||||
| /* Read string `s' from stream `str'. */ | ||||
| static void expect(std::istream & str, const string & s) | ||||
| { | ||||
|     char s2[s.size()]; | ||||
|     str.read(s2, s.size()); | ||||
|     if (string(s2, s.size()) != s) | ||||
|         throw FormatError(format("expected string ‘%1%’") % s); | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| /* Read a C-style string from stream `str'. */ | ||||
| static string parseString(std::istream & str) | ||||
| { | ||||
|     string res; | ||||
|     expect(str, "\""); | ||||
|     int c; | ||||
|     while ((c = str.get()) != '"') | ||||
|         if (c == '\\') { | ||||
|             c = str.get(); | ||||
|             if (c == 'n') res += '\n'; | ||||
|             else if (c == 'r') res += '\r'; | ||||
|             else if (c == 't') res += '\t'; | ||||
|             else res += c; | ||||
|         } | ||||
|         else res += c; | ||||
|     return res; | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| static Path parsePath(std::istream & str) | ||||
| { | ||||
|     string s = parseString(str); | ||||
|  | @ -96,6 +128,20 @@ static Path parsePath(std::istream & str) | |||
| } | ||||
| 
 | ||||
| 
 | ||||
| static bool endOfList(std::istream & str) | ||||
| { | ||||
|     if (str.peek() == ',') { | ||||
|         str.get(); | ||||
|         return false; | ||||
|     } | ||||
|     if (str.peek() == ']') { | ||||
|         str.get(); | ||||
|         return true; | ||||
|     } | ||||
|     return false; | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| static StringSet parseStrings(std::istream & str, bool arePaths) | ||||
| { | ||||
|     StringSet res; | ||||
|  |  | |||
|  | @ -1087,47 +1087,6 @@ bool hasSuffix(const string & s, const string & suffix) | |||
| } | ||||
| 
 | ||||
| 
 | ||||
| void expect(std::istream & str, const string & s) | ||||
| { | ||||
|     char s2[s.size()]; | ||||
|     str.read(s2, s.size()); | ||||
|     if (string(s2, s.size()) != s) | ||||
|         throw FormatError(format("expected string ‘%1%’") % s); | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| string parseString(std::istream & str) | ||||
| { | ||||
|     string res; | ||||
|     expect(str, "\""); | ||||
|     int c; | ||||
|     while ((c = str.get()) != '"') | ||||
|         if (c == '\\') { | ||||
|             c = str.get(); | ||||
|             if (c == 'n') res += '\n'; | ||||
|             else if (c == 'r') res += '\r'; | ||||
|             else if (c == 't') res += '\t'; | ||||
|             else res += c; | ||||
|         } | ||||
|         else res += c; | ||||
|     return res; | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| bool endOfList(std::istream & str) | ||||
| { | ||||
|     if (str.peek() == ',') { | ||||
|         str.get(); | ||||
|         return false; | ||||
|     } | ||||
|     if (str.peek() == ']') { | ||||
|         str.get(); | ||||
|         return true; | ||||
|     } | ||||
|     return false; | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| string decodeOctalEscaped(const string & s) | ||||
| { | ||||
|     string r; | ||||
|  |  | |||
|  | @ -334,20 +334,6 @@ bool hasPrefix(const string & s, const string & prefix); | |||
| bool hasSuffix(const string & s, const string & suffix); | ||||
| 
 | ||||
| 
 | ||||
| /* Read string `s' from stream `str'. */ | ||||
| void expect(std::istream & str, const string & s); | ||||
| 
 | ||||
| MakeError(FormatError, Error) | ||||
| 
 | ||||
| 
 | ||||
| /* Read a C-style string from stream `str'. */ | ||||
| string parseString(std::istream & str); | ||||
| 
 | ||||
| 
 | ||||
| /* Utility function used to parse legacy ATerms. */ | ||||
| bool endOfList(std::istream & str); | ||||
| 
 | ||||
| 
 | ||||
| /* Escape a string that contains octal-encoded escape codes such as
 | ||||
|    used in /etc/fstab and /proc/mounts (e.g. "foo\040bar" decodes to | ||||
|    "foo bar"). */ | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue