Comments (2)
public static IEnumerable<string> ParseLine(string line)
{
if (string.IsNullOrEmpty(line))
{
yield break;
}
var tokenBuilder = new StringBuilder();
var inToken= false;
var inQuotes = false;
// Iterate through every character in the line
for (var i = 0; i < line.Length; i++)
{
var character = line[i];
// If we are not currently inside a column
if (!inToken)
{
// If the current character is a quote then the token value is contained within
// quotes, otherwise append the next character
inToken = true;
if (character == '\'')
{
inQuotes = true;
continue;
}
}
// If we are in between quotes
if (inQuotes)
{
if (i + 1 == line.Length)
{
break;
}
if (character == '\'' && line[i + 1] == ' ') // quotes end
{
inQuotes = false;
inToken = false;
i++; //skip next
}
else if (character == '\'' && line[i + 1] == '\'') // quotes
{
i++; //skip next
}
else if (character == '\'')
{
throw new ArgumentException($"unable to escape {line}");
}
}
else if (character == ' ')
{
inToken = false;
}
// If we are no longer in the token clear the builder and add the columns to the list
if (!inToken)
{
if (tokenBuilder.Length > 0)
{
yield return tokenBuilder.ToString();
tokenBuilder.Clear();
}
}
else
{
tokenBuilder.Append(character);
}
}
if (tokenBuilder.Length > 0)
{
yield return tokenBuilder.ToString();
tokenBuilder.Clear();
}
}
from weihanli.common.
https://github.com/WeihanLi/WeihanLi.Common/tree/1.0.60/src/WeihanLi.Common/Helpers/LineParser.cs
from weihanli.common.
Related Issues (20)
- RateLimiter HOT 1
- PipelineBuilder add support for ValueTask
- Update Random instance for a thread safe one
- ITenantIdProvider
- Add runtime info for ApplicationHelper HOT 2
- Add cancellationToken support for CommandExecutor.ExecuteAsync
- Add ContextAccessor
- JSON data builder
- ReadOnlyRepository
- Repository: orderBy multi fields support
- DecompressGZip error HOT 2
- Add net8.0 target
- 大佬 weihanli.npoi 咋不更新了 HOT 1
- Fix AOT warnings
- `CommandExecutor` enhancements
- templating enhancements HOT 1
- refactor events HOT 1
- Try kill process when the cancellationToken cancelled for executing command
- templating pipe(filter) support
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from weihanli.common.