| // Copyright 2015 The Vanadium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style |
| // license that can be found in the LICENSE file. |
| |
| package query_functions |
| |
| import ( |
| "errors" |
| "strings" |
| |
| "v.io/syncbase/v23/syncbase/nosql/internal/query/conversions" |
| "v.io/syncbase/v23/syncbase/nosql/internal/query/query_parser" |
| "v.io/v23/vdl" |
| ) |
| |
| func lowerCase(off int64, args []*query_parser.Operand) (*query_parser.Operand, error) { |
| strOp, err := conversions.ConvertValueToString(args[0]) |
| if err != nil { |
| return nil, err |
| } |
| return makeStrOp(off, strings.ToLower(strOp.Str)), nil |
| } |
| |
| func upperCase(off int64, args []*query_parser.Operand) (*query_parser.Operand, error) { |
| strOp, err := conversions.ConvertValueToString(args[0]) |
| if err != nil { |
| return nil, err |
| } |
| return makeStrOp(off, strings.ToUpper(strOp.Str)), nil |
| } |
| |
| func typeFunc(off int64, args []*query_parser.Operand) (*query_parser.Operand, error) { |
| // If operand is not an object, we can't get a type |
| if args[0].Type != query_parser.TypObject { |
| return nil, errors.New("Type function argument must be object.") |
| } |
| t := args[0].Object.Type() |
| pkg, name := vdl.SplitIdent(t.Name()) |
| return makeStrOp(off, pkg+"."+name), nil |
| } |