mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 03:52:43 +00:00 
			
		
		
		
	 1d0b464618
			
		
	
	
		1d0b464618
		
	
	
	
	
		
			
			This allows HashMap::get() to be used for value types that cannot be default constructed (e.g NonnullOwnPtr.)
		
			
				
	
	
		
			38 lines
		
	
	
	
		
			661 B
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			38 lines
		
	
	
	
		
			661 B
		
	
	
	
		
			C++
		
	
	
	
	
	
| #include <Kernel/KParams.h>
 | |
| 
 | |
| static KParams* s_the;
 | |
| 
 | |
| KParams& KParams::the()
 | |
| {
 | |
|     return *s_the;
 | |
| }
 | |
| 
 | |
| KParams::KParams(const String& cmdline)
 | |
|     : m_cmdline(cmdline)
 | |
| {
 | |
|     s_the = this;
 | |
| 
 | |
|     for (auto str : m_cmdline.split(' ')) {
 | |
|         if (str == "") {
 | |
|             continue;
 | |
|         }
 | |
| 
 | |
|         auto pair = str.split_limit('=', 2);
 | |
| 
 | |
|         if (pair.size() == 1) {
 | |
|             m_params.set(pair[0], "");
 | |
|         } else {
 | |
|             m_params.set(pair[0], pair[1]);
 | |
|         }
 | |
|     }
 | |
| }
 | |
| 
 | |
| String KParams::get(const String& key) const
 | |
| {
 | |
|     return m_params.get(key).value_or({});
 | |
| }
 | |
| 
 | |
| bool KParams::has(const String& key) const
 | |
| {
 | |
|     return m_params.contains(key);
 | |
| }
 |