Expiriments with AvaloniaEdit and tracking document changes
This commit is contained in:
parent
29a141a971
commit
6325409d25
53 changed files with 643 additions and 627 deletions
|
|
@ -1,8 +1,12 @@
|
|||
using System.Collections.ObjectModel;
|
||||
using FluentResults;
|
||||
using Npgsql;
|
||||
|
||||
namespace pgLabII.PgUtils.ConnectionStrings;
|
||||
|
||||
/// <summary>
|
||||
/// Parser for converting a libpq style connection string into a dictionary of key value pairs
|
||||
/// </summary>
|
||||
public ref struct PqConnectionStringParser
|
||||
{
|
||||
// Note possible keywords
|
||||
|
|
@ -51,64 +55,38 @@ public ref struct PqConnectionStringParser
|
|||
).Parse();
|
||||
}
|
||||
|
||||
private readonly IPqConnectionStringTokenizer tokenizer;
|
||||
private readonly Dictionary<string, string> result = new();
|
||||
private readonly IPqConnectionStringTokenizer _tokenizer;
|
||||
private readonly Dictionary<string, string> _result = new();
|
||||
|
||||
public PqConnectionStringParser(IPqConnectionStringTokenizer tokenizer)
|
||||
{
|
||||
this.tokenizer = tokenizer;
|
||||
this._tokenizer = tokenizer;
|
||||
}
|
||||
|
||||
public IDictionary<string, string> Parse()
|
||||
{
|
||||
result.Clear();
|
||||
_result.Clear();
|
||||
|
||||
while (!tokenizer.Eof)
|
||||
while (!_tokenizer.IsEof)
|
||||
ParsePair();
|
||||
|
||||
return result;
|
||||
return _result;
|
||||
}
|
||||
|
||||
private void ParsePair()
|
||||
private Result ParsePair()
|
||||
{
|
||||
string kw = tokenizer.GetKeyword();
|
||||
tokenizer.ConsumeEquals();
|
||||
string v = tokenizer.GetValue();
|
||||
result.Add(kw, v);
|
||||
//switch (kw)
|
||||
//{
|
||||
// case "host":
|
||||
// case "hostaddr":
|
||||
// result.Host = v.ToString();
|
||||
// break;
|
||||
// case "port":
|
||||
// result.Port = int.Parse(v);
|
||||
// break;
|
||||
// case "dbname":
|
||||
// result.Database = v.ToString();
|
||||
// break;
|
||||
// case "user":
|
||||
// result.Username = v.ToString();
|
||||
// break;
|
||||
// case "password":
|
||||
// result.Password = v.ToString();
|
||||
// break;
|
||||
// case "connect_timeout":
|
||||
// result.Timeout = int.Parse(v);
|
||||
// break;
|
||||
// case "application_name":
|
||||
// result.ApplicationName = v.ToString();
|
||||
// break;
|
||||
// case "options":
|
||||
// result.Options = v.ToString();
|
||||
// break;
|
||||
// case "sslmode":
|
||||
// result.SslMode = ToSslMode(v);
|
||||
// break;
|
||||
// default:
|
||||
// // Todo what do we do with values we do not support/recognize?
|
||||
// break;
|
||||
//}
|
||||
var kwResult = _tokenizer.GetKeyword();
|
||||
if (kwResult.IsFailed)
|
||||
return kwResult.ToResult();
|
||||
var result = _tokenizer.ConsumeEquals();
|
||||
if (result.IsFailed)
|
||||
return result;
|
||||
var valResult = _tokenizer.GetValue();
|
||||
if (valResult.IsFailed)
|
||||
return valResult.ToResult();
|
||||
|
||||
_result.Add(kwResult.Value, valResult.Value);
|
||||
return Result.Ok();
|
||||
}
|
||||
|
||||
private SslMode ToSslMode(ReadOnlySpan<char> v)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue