Skip to content

Commit

Permalink
Add lc/uc/fc to column methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Fernando Corrêa de Oliveira committed Jan 3, 2025
1 parent 9cf2128 commit 1b4b401
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -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
Expand Down
30 changes: 30 additions & 0 deletions lib/Red/AST/StringFuncs.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,33 @@ class Red::AST::Index does Red::AST::StringFunction {
Red::AST::Function.new: :func<INSTR>, :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<LOWER>, :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<UPPER>, :args[$!string]
}
}
15 changes: 15 additions & 0 deletions lib/Red/ColumnMethods.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1b4b401

Please sign in to comment.