diff --git a/Changes b/Changes index 34901452..5137425b 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,7 @@ Revision history for Red {{$NEXT}} + - Add uc/lc/fc to column methods 0.1.73 2024-10-14T21:52:50+01:00 - Fix create child with no ids diff --git a/lib/Red/AST/StringFuncs.rakumod b/lib/Red/AST/StringFuncs.rakumod index 2d82f371..dc583919 100644 --- a/lib/Red/AST/StringFuncs.rakumod +++ b/lib/Red/AST/StringFuncs.rakumod @@ -41,3 +41,33 @@ class Red::AST::Index does Red::AST::StringFunction { Red::AST::Function.new: :func, :args[$!base, ast-value($!needle)] } } + +#| Represents a lc/fc call +class Red::AST::Lowercase does Red::AST::StringFunction { + has Red::AST $.string; + + method returns { Str } + method find-column-name { + $!string.find-column-name + } + method args {$!string} + + method default-implementation { + Red::AST::Function.new: :func, :args[$!string] + } +} + +#| Represents a uc call +class Red::AST::Uppercase does Red::AST::StringFunction { + has Red::AST $.string; + + method returns { Str } + method find-column-name { + $!string.find-column-name + } + method args {$!string} + + method default-implementation { + Red::AST::Function.new: :func, :args[$!string] + } +} diff --git a/lib/Red/ColumnMethods.rakumod b/lib/Red/ColumnMethods.rakumod index ba6b01e4..c218c167 100644 --- a/lib/Red/ColumnMethods.rakumod +++ b/lib/Red/ColumnMethods.rakumod @@ -42,6 +42,21 @@ multi method contains(Str() $text is rw) { Red::AST::Like.new(self, ast-value("%{ $text }%"), :bind-left) but Red::ColumnMethods } +#| Return a lowercased string +multi method lc($string:) { + Red::AST::Lowercase.new(:$string) but Red::ColumnMethods +} + +#| Return a lowercased string +multi method fc($string:) { + Red::AST::Lowercase.new(:$string) but Red::ColumnMethods +} + +#| Return a uppercased string +multi method uc($string:) { + Red::AST::Uppercase.new(:$string) but Red::ColumnMethods +} + #| Return a substring of the column value multi method substr($base where { .returns ~~ Str }: $offset = ast-value(0), $size?) { Red::AST::Substring.new(:$base, :$offset, |(:$size with $size)) but Red::ColumnMethods