Skip to content

Commit

Permalink
Add Length, ToLower and ToUpper for strings and convenience extensions.
Browse files Browse the repository at this point in the history
  • Loading branch information
danielcweber committed Feb 27, 2025
1 parent a6cc6db commit 102ad26
Show file tree
Hide file tree
Showing 188 changed files with 2,314 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Core/Extensions/StringGremlinQueryExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ public static IStringGremlinQuery<string> Concat(this IGremlinQueryBase<string>
.ChangeQueryType<IStringGremlinQuery<string>>()
.Concat(stringTraversals);

public static IGremlinQuery<int> Length(this IGremlinQueryBase<string> query) => query
.AsAdmin()
.ChangeQueryType<IStringGremlinQuery<string>>()
.Length();

public static IStringGremlinQuery<string> Substring(this IGremlinQueryBase<string> query, int startIndex) => query
.AsAdmin()
.ChangeQueryType<IStringGremlinQuery<string>>()
Expand All @@ -26,5 +31,15 @@ public static IStringGremlinQuery<string> Substring(this IGremlinQueryBase<strin
.AsAdmin()
.ChangeQueryType<IStringGremlinQuery<string>>()
.Substring(range);

public static IStringGremlinQuery<string> ToLower(this IGremlinQueryBase<string> query) => query
.AsAdmin()
.ChangeQueryType<IStringGremlinQuery<string>>()
.ToLower();

public static IStringGremlinQuery<string> ToUpper(this IGremlinQueryBase<string> query) => query
.AsAdmin()
.ChangeQueryType<IStringGremlinQuery<string>>()
.ToUpper();
}
}
19 changes: 19 additions & 0 deletions src/Core/Queries/GremlinQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,25 @@ private GremlinQuery<string, object, object, IGremlinQueryBase> AsString() => th
.WithNewProjection(Projection.Value)
.AsAuto<string>());

private GremlinQuery<int, object, object, IGremlinQueryBase> Length() => this
.Continue()
.Build(static builder => builder
.AddStep(LengthStep.Instance)
.WithNewProjection(Projection.Value)
.AsAuto<int>());

private GremlinQuery<T1, T2, T3, T4> ToLower() => this
.Continue()
.Build(static builder => builder
.AddStep(ToLowerStep.Instance)
.WithNewProjection(Projection.Value));

private GremlinQuery<T1, T2, T3, T4> ToUpper() => this
.Continue()
.Build(static builder => builder
.AddStep(ToUpperStep.Instance)
.WithNewProjection(Projection.Value));

private GremlinQuery<T1, T2, T3, T4> Barrier() => this
.Continue()
.Build(static builder => builder
Expand Down
6 changes: 6 additions & 0 deletions src/Core/Queries/GremlinQuery.explicit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -476,5 +476,11 @@ IStringGremlinQuery<T1> IStringGremlinQuery<T1>.Substring(int startIndex, int le
: throw new ArgumentOutOfRangeException();

IStringGremlinQuery<T1> IStringGremlinQuery<T1>.Substring(Range range) => Substring(range);

IGremlinQuery<int> IStringGremlinQuery<T1>.Length() => Length();

IStringGremlinQuery<T1> IStringGremlinQuery<T1>.ToLower() => ToLower();

IStringGremlinQuery<T1> IStringGremlinQuery<T1>.ToUpper() => ToUpper();
}
}
6 changes: 6 additions & 0 deletions src/Core/Queries/Interfaces/IStringGremlinQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@ public interface IStringGremlinQuery<TString> : IGremlinQueryBaseRec<TString, IS

IStringGremlinQuery<TString> Concat(params Func<IStringGremlinQuery<TString>, IGremlinQueryBase<TString>>[] stringTraversals);

IGremlinQuery<int> Length();

IStringGremlinQuery<TString> Substring(int startIndex);

IStringGremlinQuery<TString> Substring(int startIndex, int length);

IStringGremlinQuery<TString> Substring(Range range);

IStringGremlinQuery<TString> ToLower();

IStringGremlinQuery<TString> ToUpper();
}
}
3 changes: 3 additions & 0 deletions src/Core/Serialization/Instructions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ internal static class Instructions
public static readonly Instruction inV = new(nameof(inV));
public static readonly Instruction key = new(nameof(key));
public static readonly Instruction label = new(nameof(label));
public static readonly Instruction length = new(nameof(length));
public static readonly Instruction max = new(nameof(max));
public static readonly Instruction mean = new(nameof(mean));
public static readonly Instruction min = new(nameof(min));
Expand All @@ -33,6 +34,8 @@ internal static class Instructions
public static readonly Instruction profile = new(nameof(profile));
public static readonly Instruction simplePath = new(nameof(simplePath));
public static readonly Instruction sum = new(nameof(sum));
public static readonly Instruction toLower = new(nameof(toLower));
public static readonly Instruction toUpper = new(nameof(toUpper));
public static readonly Instruction tree = new(nameof(tree));
public static readonly Instruction unfold = new(nameof(unfold));
public static readonly Instruction value = new(nameof(value));
Expand Down
3 changes: 3 additions & 0 deletions src/Core/Serialization/Serializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ private static ITransformer AddDefaultStepConverters(this ITransformer serialize
: step.Predicate))
.Add<KeyStep>((_, _, _, _) => key)
.Add<LabelStep>((_, _, _, _) => label)
.Add<LengthStep>((step, env, _, recurse) => length)
.Add<LimitStep>((step, env, _, recurse) => step.Scope.Equals(Scope.Local)
? CreateInstruction("limit", recurse, env, step.Scope, step.Count)
: CreateInstruction("limit", recurse, env, step.Count))
Expand Down Expand Up @@ -546,6 +547,8 @@ private static ITransformer AddDefaultStepConverters(this ITransformer serialize
? CreateInstruction("tail", recurse, env, step.Scope, step.Count)
: CreateInstruction("tail", recurse, env, step.Count))
.Add<TimesStep>((step, env, _, recurse) => CreateInstruction("times", recurse, env, step.Count))
.Add<ToLowerStep>((step, env, _, recurse) => toLower)
.Add<ToUpperStep>((step, env, _, recurse) => toUpper)
.Add<TreeStep>((_, _, _, _) => tree)
.Add<TreeStep.ByIdentityStep>((_, _, _, _) => by)
.Add<TreeStep.ByKeyStep>((step, env, _, recurse) => CreateInstruction("by", recurse, env, step.Key))
Expand Down
12 changes: 12 additions & 0 deletions src/Core/Steps/LengthStep.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace ExRam.Gremlinq.Core.Steps
{
public sealed class LengthStep : Step
{
public static readonly LengthStep Instance = new();

private LengthStep()
{

}
}
}
12 changes: 12 additions & 0 deletions src/Core/Steps/ToLowerStep.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace ExRam.Gremlinq.Core.Steps
{
public sealed class ToLowerStep : Step
{
public static readonly ToLowerStep Instance = new();

private ToLowerStep()
{

}
}
}
12 changes: 12 additions & 0 deletions src/Core/Steps/ToUpperStep.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace ExRam.Gremlinq.Core.Steps
{
public sealed class ToUpperStep : Step
{
public static readonly ToUpperStep Instance = new();

private ToUpperStep()
{

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
g.inject('aBcDeFg').asString().length()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
g.inject('aBcDeFg').length()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
g.inject('aBcDeFg').asString().toLower()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
g.inject('aBcDeFg').toLower()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
g.inject('aBcDeFg').asString().toUpper()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
g.inject('aBcDeFg').toUpper()
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
StepInstructions: [
{
OperatorName: inject,
Arguments: [
aBcDeFg
]
},
{
OperatorName: asString
},
{
OperatorName: length
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
StepInstructions: [
{
OperatorName: inject,
Arguments: [
aBcDeFg
]
},
{
OperatorName: length
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
StepInstructions: [
{
OperatorName: inject,
Arguments: [
aBcDeFg
]
},
{
OperatorName: asString
},
{
OperatorName: toLower
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
StepInstructions: [
{
OperatorName: inject,
Arguments: [
aBcDeFg
]
},
{
OperatorName: toLower
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
StepInstructions: [
{
OperatorName: inject,
Arguments: [
aBcDeFg
]
},
{
OperatorName: asString
},
{
OperatorName: toUpper
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
StepInstructions: [
{
OperatorName: inject,
Arguments: [
aBcDeFg
]
},
{
OperatorName: toUpper
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
StepInstructions: [
{
OperatorName: inject,
Arguments: [
aBcDeFg
]
},
{
OperatorName: asString
},
{
OperatorName: length
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
StepInstructions: [
{
OperatorName: inject,
Arguments: [
aBcDeFg
]
},
{
OperatorName: length
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
StepInstructions: [
{
OperatorName: inject,
Arguments: [
aBcDeFg
]
},
{
OperatorName: asString
},
{
OperatorName: toLower
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
StepInstructions: [
{
OperatorName: inject,
Arguments: [
aBcDeFg
]
},
{
OperatorName: toLower
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
StepInstructions: [
{
OperatorName: inject,
Arguments: [
aBcDeFg
]
},
{
OperatorName: asString
},
{
OperatorName: toUpper
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
StepInstructions: [
{
OperatorName: inject,
Arguments: [
aBcDeFg
]
},
{
OperatorName: toUpper
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!application/vnd.gremlin-v2.0+json{"requestId":"12345678-9012-3456-7890-123456789012","op":"bytecode","processor":"traversal","args":{"gremlin":{"@type":"g:Bytecode","@value":{"step":[["inject","aBcDeFg"],["asString"],["length"]]}},"aliases":{"g":"g"}}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!application/vnd.gremlin-v2.0+json{"requestId":"12345678-9012-3456-7890-123456789012","op":"bytecode","processor":"traversal","args":{"gremlin":{"@type":"g:Bytecode","@value":{"step":[["inject","aBcDeFg"],["length"]]}},"aliases":{"g":"g"}}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!application/vnd.gremlin-v2.0+json{"requestId":"12345678-9012-3456-7890-123456789012","op":"bytecode","processor":"traversal","args":{"gremlin":{"@type":"g:Bytecode","@value":{"step":[["inject","aBcDeFg"],["asString"],["toLower"]]}},"aliases":{"g":"g"}}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!application/vnd.gremlin-v2.0+json{"requestId":"12345678-9012-3456-7890-123456789012","op":"bytecode","processor":"traversal","args":{"gremlin":{"@type":"g:Bytecode","@value":{"step":[["inject","aBcDeFg"],["toLower"]]}},"aliases":{"g":"g"}}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!application/vnd.gremlin-v2.0+json{"requestId":"12345678-9012-3456-7890-123456789012","op":"bytecode","processor":"traversal","args":{"gremlin":{"@type":"g:Bytecode","@value":{"step":[["inject","aBcDeFg"],["asString"],["toUpper"]]}},"aliases":{"g":"g"}}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!application/vnd.gremlin-v2.0+json{"requestId":"12345678-9012-3456-7890-123456789012","op":"bytecode","processor":"traversal","args":{"gremlin":{"@type":"g:Bytecode","@value":{"step":[["inject","aBcDeFg"],["toUpper"]]}},"aliases":{"g":"g"}}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!application/vnd.gremlin-v3.0+json{"requestId":"12345678-9012-3456-7890-123456789012","op":"bytecode","processor":"traversal","args":{"gremlin":{"@type":"g:Bytecode","@value":{"step":[["inject","aBcDeFg"],["asString"],["length"]]}},"aliases":{"g":"g"}}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!application/vnd.gremlin-v3.0+json{"requestId":"12345678-9012-3456-7890-123456789012","op":"bytecode","processor":"traversal","args":{"gremlin":{"@type":"g:Bytecode","@value":{"step":[["inject","aBcDeFg"],["length"]]}},"aliases":{"g":"g"}}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!application/vnd.gremlin-v3.0+json{"requestId":"12345678-9012-3456-7890-123456789012","op":"bytecode","processor":"traversal","args":{"gremlin":{"@type":"g:Bytecode","@value":{"step":[["inject","aBcDeFg"],["asString"],["toLower"]]}},"aliases":{"g":"g"}}}
Loading

0 comments on commit 102ad26

Please sign in to comment.