| 
									
										
										
										
											2008-07-29 19:02:49 -07:00
										 |  |  | // Copyright 2009 The Go Authors.  All rights reserved. | 
					
						
							|  |  |  | // Use of this source code is governed by a BSD-style | 
					
						
							|  |  |  | // license that can be found in the LICENSE file. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | package Utils | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-04 15:37:47 -07:00
										 |  |  | export func BaseName(s string) string { | 
					
						
							| 
									
										
										
										
											2008-07-29 19:02:49 -07:00
										 |  |  | 	// TODO this is not correct for non-ASCII strings! | 
					
						
							|  |  |  | 	i := len(s) - 1; | 
					
						
							|  |  |  | 	for i >= 0 && s[i] != '/' { | 
					
						
							|  |  |  | 		if s[i] > 128 { | 
					
						
							|  |  |  | 			panic "non-ASCII string" | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		i--; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return s[i + 1 : len(s)]; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-04 15:37:47 -07:00
										 |  |  | export func FixExt(s string) string { | 
					
						
							| 
									
										
										
										
											2008-07-29 19:02:49 -07:00
										 |  |  | 	i := len(s) - 3;  // 3 == len(".go"); | 
					
						
							| 
									
										
										
										
											2008-07-31 15:35:25 -07:00
										 |  |  | 	if i >= 0 && s[i : len(s)] == ".go" { | 
					
						
							| 
									
										
										
										
											2008-07-29 19:02:49 -07:00
										 |  |  | 		s = s[0 : i]; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return s + ".7"; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2008-07-30 17:36:03 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-04 15:37:47 -07:00
										 |  |  | export func GetEnv(key string) string { | 
					
						
							| 
									
										
										
										
											2008-07-30 17:36:03 -07:00
										 |  |  | 	n := len(key); | 
					
						
							|  |  |  | 	for i := 0; i < sys.envc(); i++ { | 
					
						
							|  |  |  | 		v := sys.envv(i); | 
					
						
							|  |  |  | 		if v[0 : n] == key { | 
					
						
							|  |  |  | 			return v[n + 1 : len(v)];  // +1: skip "=" | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return ""; | 
					
						
							|  |  |  | } |