Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
|
|
|
/*
|
|
|
|
*
|
2022-02-21 03:32:53 +00:00
|
|
|
* Query Generator Library
|
|
|
|
* WIP Under Construction
|
|
|
|
* Copyright Azareal 2017 - 2020
|
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
|
|
|
*
|
|
|
|
*/
|
2017-06-13 07:12:58 +00:00
|
|
|
package qgen
|
2017-06-12 09:03:14 +00:00
|
|
|
|
2017-10-16 07:32:58 +00:00
|
|
|
import (
|
2022-02-21 03:32:53 +00:00
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
//"fmt"
|
2017-10-16 07:32:58 +00:00
|
|
|
)
|
2017-06-12 09:03:14 +00:00
|
|
|
|
2019-02-23 06:29:19 +00:00
|
|
|
// TODO: Add support for numbers and strings?
|
2019-12-31 21:57:54 +00:00
|
|
|
func processColumns(colStr string) (columns []DBColumn) {
|
2022-02-21 03:32:53 +00:00
|
|
|
if colStr == "" {
|
|
|
|
return columns
|
|
|
|
}
|
|
|
|
colStr = strings.Replace(colStr, " as ", " AS ", -1)
|
|
|
|
for _, segment := range strings.Split(colStr, ",") {
|
|
|
|
var outCol DBColumn
|
|
|
|
dotHalves := strings.Split(strings.TrimSpace(segment), ".")
|
|
|
|
|
|
|
|
var halves []string
|
|
|
|
if len(dotHalves) == 2 {
|
|
|
|
outCol.Table = dotHalves[0]
|
|
|
|
halves = strings.Split(dotHalves[1], " AS ")
|
|
|
|
} else {
|
|
|
|
halves = strings.Split(dotHalves[0], " AS ")
|
|
|
|
}
|
|
|
|
|
|
|
|
halves[0] = strings.TrimSpace(halves[0])
|
|
|
|
if len(halves) == 2 {
|
|
|
|
outCol.Alias = strings.TrimSpace(halves[1])
|
|
|
|
}
|
|
|
|
//fmt.Printf("halves: %+v\n", halves)
|
|
|
|
//fmt.Printf("halves[0]: %+v\n", halves[0])
|
|
|
|
switch {
|
|
|
|
case halves[0][0] == '(':
|
|
|
|
outCol.Type = TokenScope
|
|
|
|
outCol.Table = ""
|
|
|
|
case halves[0][len(halves[0])-1] == ')':
|
|
|
|
outCol.Type = TokenFunc
|
|
|
|
case halves[0] == "?":
|
|
|
|
outCol.Type = TokenSub
|
|
|
|
default:
|
|
|
|
outCol.Type = TokenColumn
|
|
|
|
}
|
|
|
|
|
|
|
|
outCol.Left = halves[0]
|
|
|
|
columns = append(columns, outCol)
|
|
|
|
}
|
|
|
|
return columns
|
2017-06-12 09:03:14 +00:00
|
|
|
}
|
|
|
|
|
2017-10-16 07:32:58 +00:00
|
|
|
// TODO: Allow order by statements without a direction
|
2019-12-31 21:57:54 +00:00
|
|
|
func processOrderby(orderStr string) (order []DBOrder) {
|
2022-02-21 03:32:53 +00:00
|
|
|
if orderStr == "" {
|
|
|
|
return order
|
|
|
|
}
|
|
|
|
for _, segment := range strings.Split(orderStr, ",") {
|
|
|
|
var outOrder DBOrder
|
|
|
|
halves := strings.Split(strings.TrimSpace(segment), " ")
|
|
|
|
if len(halves) != 2 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
outOrder.Column = halves[0]
|
|
|
|
outOrder.Order = strings.ToLower(halves[1])
|
|
|
|
order = append(order, outOrder)
|
|
|
|
}
|
|
|
|
return order
|
2017-06-12 09:03:14 +00:00
|
|
|
}
|
|
|
|
|
2019-12-31 21:57:54 +00:00
|
|
|
func processJoiner(joinStr string) (joiner []DBJoiner) {
|
2022-02-21 03:32:53 +00:00
|
|
|
if joinStr == "" {
|
|
|
|
return joiner
|
|
|
|
}
|
|
|
|
joinStr = strings.Replace(joinStr, " on ", " ON ", -1)
|
|
|
|
joinStr = strings.Replace(joinStr, " and ", " AND ", -1)
|
|
|
|
for _, segment := range strings.Split(joinStr, " AND ") {
|
|
|
|
var outJoin DBJoiner
|
|
|
|
var parseOffset int
|
|
|
|
var left, right string
|
|
|
|
|
|
|
|
left, parseOffset = getIdentifier(segment, parseOffset)
|
|
|
|
outJoin.Operator, parseOffset = getOperator(segment, parseOffset+1)
|
|
|
|
right, parseOffset = getIdentifier(segment, parseOffset+1)
|
|
|
|
|
|
|
|
leftColumn := strings.Split(left, ".")
|
|
|
|
rightColumn := strings.Split(right, ".")
|
|
|
|
outJoin.LeftTable = strings.TrimSpace(leftColumn[0])
|
|
|
|
outJoin.RightTable = strings.TrimSpace(rightColumn[0])
|
|
|
|
outJoin.LeftColumn = strings.TrimSpace(leftColumn[1])
|
|
|
|
outJoin.RightColumn = strings.TrimSpace(rightColumn[1])
|
|
|
|
|
|
|
|
joiner = append(joiner, outJoin)
|
|
|
|
}
|
|
|
|
return joiner
|
2017-06-12 09:03:14 +00:00
|
|
|
}
|
|
|
|
|
2020-01-01 04:15:11 +00:00
|
|
|
func (wh *DBWhere) parseNumber(seg string, i int) int {
|
2022-02-21 03:32:53 +00:00
|
|
|
//var buffer string
|
|
|
|
si := i
|
|
|
|
l := 0
|
|
|
|
for ; i < len(seg); i++ {
|
|
|
|
ch := seg[i]
|
|
|
|
if '0' <= ch && ch <= '9' {
|
|
|
|
//buffer += string(ch)
|
|
|
|
l++
|
|
|
|
} else {
|
|
|
|
i--
|
|
|
|
var str string
|
|
|
|
if l != 0 {
|
|
|
|
str = seg[si : si+l]
|
|
|
|
}
|
|
|
|
wh.Expr = append(wh.Expr, DBToken{str, TokenNumber})
|
|
|
|
return i
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return i
|
2017-11-12 11:29:23 +00:00
|
|
|
}
|
|
|
|
|
2020-01-01 01:26:15 +00:00
|
|
|
func (wh *DBWhere) parseColumn(seg string, i int) int {
|
2022-02-21 03:32:53 +00:00
|
|
|
//var buffer string
|
|
|
|
si := i
|
|
|
|
l := 0
|
|
|
|
for ; i < len(seg); i++ {
|
|
|
|
ch := seg[i]
|
|
|
|
switch {
|
|
|
|
case ('a' <= ch && ch <= 'z') || ('A' <= ch && ch <= 'Z') || ch == '.' || ch == '_':
|
|
|
|
//buffer += string(ch)
|
|
|
|
l++
|
|
|
|
case ch == '(':
|
|
|
|
var str string
|
|
|
|
if l != 0 {
|
|
|
|
str = seg[si : si+l]
|
|
|
|
}
|
|
|
|
return wh.parseFunction(seg, str, i)
|
|
|
|
default:
|
|
|
|
i--
|
|
|
|
var str string
|
|
|
|
if l != 0 {
|
|
|
|
str = seg[si : si+l]
|
|
|
|
}
|
|
|
|
wh.Expr = append(wh.Expr, DBToken{str, TokenColumn})
|
|
|
|
return i
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return i
|
2017-11-12 11:29:23 +00:00
|
|
|
}
|
|
|
|
|
2021-04-29 22:33:02 +00:00
|
|
|
func (wh *DBWhere) parseFunction(seg, buffer string, i int) int {
|
2022-02-21 03:32:53 +00:00
|
|
|
preI := i
|
|
|
|
i = skipFunctionCall(seg, i-1)
|
|
|
|
buffer += seg[preI:i] + string(seg[i])
|
|
|
|
wh.Expr = append(wh.Expr, DBToken{buffer, TokenFunc})
|
|
|
|
return i
|
2017-11-12 11:29:23 +00:00
|
|
|
}
|
|
|
|
|
2020-01-01 04:15:11 +00:00
|
|
|
func (wh *DBWhere) parseString(seg string, i int) int {
|
2022-02-21 03:32:53 +00:00
|
|
|
//var buffer string
|
|
|
|
i++
|
|
|
|
si := i
|
|
|
|
l := 0
|
|
|
|
for ; i < len(seg); i++ {
|
|
|
|
ch := seg[i]
|
|
|
|
if ch != '\'' {
|
|
|
|
//buffer += string(ch)
|
|
|
|
l++
|
|
|
|
} else {
|
|
|
|
var str string
|
|
|
|
if l != 0 {
|
|
|
|
str = seg[si : si+l]
|
|
|
|
}
|
|
|
|
wh.Expr = append(wh.Expr, DBToken{str, TokenString})
|
|
|
|
return i
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return i
|
2017-11-13 00:31:46 +00:00
|
|
|
}
|
|
|
|
|
2020-01-01 04:15:11 +00:00
|
|
|
func (wh *DBWhere) parseOperator(seg string, i int) int {
|
2022-02-21 03:32:53 +00:00
|
|
|
//var buffer string
|
|
|
|
si := i
|
|
|
|
l := 0
|
|
|
|
for ; i < len(seg); i++ {
|
|
|
|
ch := seg[i]
|
|
|
|
if isOpByte(ch) {
|
|
|
|
//buffer += string(ch)
|
|
|
|
l++
|
|
|
|
} else {
|
|
|
|
i--
|
|
|
|
var str string
|
|
|
|
if l != 0 {
|
|
|
|
str = seg[si : si+l]
|
|
|
|
}
|
|
|
|
wh.Expr = append(wh.Expr, DBToken{str, TokenOp})
|
|
|
|
return i
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return i
|
2017-11-13 00:31:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Make this case insensitive
|
|
|
|
func normalizeAnd(in string) string {
|
2022-02-21 03:32:53 +00:00
|
|
|
in = strings.Replace(in, " and ", " AND ", -1)
|
|
|
|
return strings.Replace(in, " && ", " AND ", -1)
|
2018-03-31 05:25:27 +00:00
|
|
|
}
|
|
|
|
func normalizeOr(in string) string {
|
2022-02-21 03:32:53 +00:00
|
|
|
in = strings.Replace(in, " or ", " OR ", -1)
|
|
|
|
return strings.Replace(in, " || ", " OR ", -1)
|
2017-11-13 00:31:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Write tests for this
|
2019-12-31 21:57:54 +00:00
|
|
|
func processWhere(whereStr string) (where []DBWhere) {
|
2022-02-21 03:32:53 +00:00
|
|
|
if whereStr == "" {
|
|
|
|
return where
|
|
|
|
}
|
|
|
|
whereStr = normalizeAnd(whereStr)
|
|
|
|
whereStr = normalizeOr(whereStr)
|
|
|
|
|
|
|
|
for _, seg := range strings.Split(whereStr, " AND ") {
|
|
|
|
tmpWhere := &DBWhere{[]DBToken{}}
|
|
|
|
seg += ")"
|
|
|
|
for i := 0; i < len(seg); i++ {
|
|
|
|
ch := seg[i]
|
|
|
|
switch {
|
|
|
|
case '0' <= ch && ch <= '9':
|
|
|
|
i = tmpWhere.parseNumber(seg, i)
|
|
|
|
// TODO: Sniff the third byte offset from char or it's non-existent to avoid matching uppercase strings which start with OR
|
|
|
|
case ch == 'O' && (i+1) < len(seg) && seg[i+1] == 'R':
|
|
|
|
tmpWhere.Expr = append(tmpWhere.Expr, DBToken{"OR", TokenOr})
|
|
|
|
i += 1
|
|
|
|
case ch == 'N' && (i+2) < len(seg) && seg[i+1] == 'O' && seg[i+2] == 'T':
|
|
|
|
tmpWhere.Expr = append(tmpWhere.Expr, DBToken{"NOT", TokenNot})
|
|
|
|
i += 2
|
|
|
|
case ch == 'L' && (i+3) < len(seg) && seg[i+1] == 'I' && seg[i+2] == 'K' && seg[i+3] == 'E':
|
|
|
|
tmpWhere.Expr = append(tmpWhere.Expr, DBToken{"LIKE", TokenLike})
|
|
|
|
i += 3
|
|
|
|
case ('a' <= ch && ch <= 'z') || ('A' <= ch && ch <= 'Z') || ch == '_':
|
|
|
|
i = tmpWhere.parseColumn(seg, i)
|
|
|
|
case ch == '\'':
|
|
|
|
i = tmpWhere.parseString(seg, i)
|
|
|
|
case ch == ')' && i < (len(seg)-1):
|
|
|
|
tmpWhere.Expr = append(tmpWhere.Expr, DBToken{")", TokenOp})
|
|
|
|
case isOpByte(ch):
|
|
|
|
i = tmpWhere.parseOperator(seg, i)
|
|
|
|
case ch == '?':
|
|
|
|
tmpWhere.Expr = append(tmpWhere.Expr, DBToken{"?", TokenSub})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
where = append(where, *tmpWhere)
|
|
|
|
}
|
|
|
|
return where
|
2017-06-12 09:03:14 +00:00
|
|
|
}
|
|
|
|
|
2020-01-01 04:15:11 +00:00
|
|
|
func (set *DBSetter) parseNumber(seg string, i int) int {
|
2022-02-21 03:32:53 +00:00
|
|
|
//var buffer string
|
|
|
|
si := i
|
|
|
|
l := 0
|
|
|
|
for ; i < len(seg); i++ {
|
|
|
|
ch := seg[i]
|
|
|
|
if '0' <= ch && ch <= '9' {
|
|
|
|
//buffer += string(ch)
|
|
|
|
l++
|
|
|
|
} else {
|
|
|
|
var str string
|
|
|
|
if l != 0 {
|
|
|
|
str = seg[si : si+l]
|
|
|
|
}
|
|
|
|
set.Expr = append(set.Expr, DBToken{str, TokenNumber})
|
|
|
|
return i
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return i
|
2017-11-13 00:31:46 +00:00
|
|
|
}
|
|
|
|
|
2020-01-01 04:15:11 +00:00
|
|
|
func (set *DBSetter) parseColumn(seg string, i int) int {
|
2022-02-21 03:32:53 +00:00
|
|
|
//var buffer string
|
|
|
|
si := i
|
|
|
|
l := 0
|
|
|
|
for ; i < len(seg); i++ {
|
|
|
|
ch := seg[i]
|
|
|
|
switch {
|
|
|
|
case ('a' <= ch && ch <= 'z') || ('A' <= ch && ch <= 'Z') || ch == '_':
|
|
|
|
//buffer += string(ch)
|
|
|
|
l++
|
|
|
|
case ch == '(':
|
|
|
|
var str string
|
|
|
|
if l != 0 {
|
|
|
|
str = seg[si : si+l]
|
|
|
|
}
|
|
|
|
return set.parseFunction(seg, str, i)
|
|
|
|
default:
|
|
|
|
i--
|
|
|
|
var str string
|
|
|
|
if l != 0 {
|
|
|
|
str = seg[si : si+l]
|
|
|
|
}
|
|
|
|
set.Expr = append(set.Expr, DBToken{str, TokenColumn})
|
|
|
|
return i
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return i
|
2017-11-13 00:31:46 +00:00
|
|
|
}
|
|
|
|
|
2021-04-29 22:33:02 +00:00
|
|
|
func (set *DBSetter) parseFunction(segment, buffer string, i int) int {
|
2022-02-21 03:32:53 +00:00
|
|
|
preI := i
|
|
|
|
i = skipFunctionCall(segment, i-1)
|
|
|
|
buffer += segment[preI:i] + string(segment[i])
|
|
|
|
set.Expr = append(set.Expr, DBToken{buffer, TokenFunc})
|
|
|
|
return i
|
2017-11-13 00:31:46 +00:00
|
|
|
}
|
|
|
|
|
2020-01-01 04:15:11 +00:00
|
|
|
func (set *DBSetter) parseString(seg string, i int) int {
|
2022-02-21 03:32:53 +00:00
|
|
|
//var buffer string
|
|
|
|
i++
|
|
|
|
si := i
|
|
|
|
l := 0
|
|
|
|
for ; i < len(seg); i++ {
|
|
|
|
ch := seg[i]
|
|
|
|
if ch != '\'' {
|
|
|
|
//buffer += string(ch)
|
|
|
|
l++
|
|
|
|
} else {
|
|
|
|
var str string
|
|
|
|
if l != 0 {
|
|
|
|
str = seg[si : si+l]
|
|
|
|
}
|
|
|
|
set.Expr = append(set.Expr, DBToken{str, TokenString})
|
|
|
|
return i
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return i
|
2017-11-13 00:31:46 +00:00
|
|
|
}
|
|
|
|
|
2020-01-01 04:15:11 +00:00
|
|
|
func (set *DBSetter) parseOperator(seg string, i int) int {
|
2022-02-21 03:32:53 +00:00
|
|
|
//var buffer string
|
|
|
|
si := i
|
|
|
|
l := 0
|
|
|
|
for ; i < len(seg); i++ {
|
|
|
|
ch := seg[i]
|
|
|
|
if isOpByte(ch) {
|
|
|
|
//buffer += string(ch)
|
|
|
|
l++
|
|
|
|
} else {
|
|
|
|
i--
|
|
|
|
var str string
|
|
|
|
if l != 0 {
|
|
|
|
str = seg[si : si+l]
|
|
|
|
}
|
|
|
|
set.Expr = append(set.Expr, DBToken{str, TokenOp})
|
|
|
|
return i
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return i
|
2017-11-13 00:31:46 +00:00
|
|
|
}
|
|
|
|
|
2017-11-12 05:25:04 +00:00
|
|
|
func processSet(setstr string) (setter []DBSetter) {
|
2022-02-21 03:32:53 +00:00
|
|
|
if setstr == "" {
|
|
|
|
return setter
|
|
|
|
}
|
|
|
|
|
|
|
|
// First pass, splitting the string by commas while ignoring the innards of functions
|
|
|
|
var setset []string
|
|
|
|
var buffer string
|
|
|
|
var lastItem int
|
|
|
|
setstr += ","
|
|
|
|
for i := 0; i < len(setstr); i++ {
|
|
|
|
if setstr[i] == '(' {
|
|
|
|
i = skipFunctionCall(setstr, i-1)
|
|
|
|
setset = append(setset, setstr[lastItem:i+1])
|
|
|
|
buffer = ""
|
|
|
|
lastItem = i + 2
|
|
|
|
} else if setstr[i] == ',' && buffer != "" {
|
|
|
|
setset = append(setset, buffer)
|
|
|
|
buffer = ""
|
|
|
|
lastItem = i + 1
|
|
|
|
} else if (setstr[i] > 32) && setstr[i] != ',' && setstr[i] != ')' {
|
|
|
|
buffer += string(setstr[i])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Second pass. Break this setitem into manageable chunks
|
|
|
|
for _, setitem := range setset {
|
|
|
|
halves := strings.Split(setitem, "=")
|
|
|
|
if len(halves) != 2 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
tmpSetter := &DBSetter{Column: strings.TrimSpace(halves[0])}
|
|
|
|
segment := halves[1] + ")"
|
|
|
|
|
|
|
|
for i := 0; i < len(segment); i++ {
|
|
|
|
ch := segment[i]
|
|
|
|
switch {
|
|
|
|
case '0' <= ch && ch <= '9':
|
|
|
|
i = tmpSetter.parseNumber(segment, i)
|
|
|
|
case ('a' <= ch && ch <= 'z') || ('A' <= ch && ch <= 'Z') || ch == '_':
|
|
|
|
i = tmpSetter.parseColumn(segment, i)
|
|
|
|
case ch == '\'':
|
|
|
|
i = tmpSetter.parseString(segment, i)
|
|
|
|
case isOpByte(ch):
|
|
|
|
i = tmpSetter.parseOperator(segment, i)
|
|
|
|
case ch == '?':
|
|
|
|
tmpSetter.Expr = append(tmpSetter.Expr, DBToken{"?", TokenSub})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
setter = append(setter, *tmpSetter)
|
|
|
|
}
|
|
|
|
return setter
|
2017-06-12 09:03:14 +00:00
|
|
|
}
|
|
|
|
|
2019-12-31 21:57:54 +00:00
|
|
|
func processLimit(limitStr string) (limit DBLimit) {
|
2022-02-21 03:32:53 +00:00
|
|
|
halves := strings.Split(limitStr, ",")
|
|
|
|
if len(halves) == 2 {
|
|
|
|
limit.Offset = halves[0]
|
|
|
|
limit.MaxCount = halves[1]
|
|
|
|
} else {
|
|
|
|
limit.MaxCount = halves[0]
|
|
|
|
}
|
|
|
|
return limit
|
2017-06-15 11:40:35 +00:00
|
|
|
}
|
|
|
|
|
2019-12-31 21:57:54 +00:00
|
|
|
func isOpByte(ch byte) bool {
|
2022-02-21 03:32:53 +00:00
|
|
|
return ch == '<' || ch == '>' || ch == '=' || ch == '!' || ch == '*' || ch == '%' || ch == '+' || ch == '-' || ch == '/' || ch == '(' || ch == ')'
|
2017-06-12 09:03:14 +00:00
|
|
|
}
|
|
|
|
|
2019-12-31 21:57:54 +00:00
|
|
|
func isOpRune(ch rune) bool {
|
2022-02-21 03:32:53 +00:00
|
|
|
return ch == '<' || ch == '>' || ch == '=' || ch == '!' || ch == '*' || ch == '%' || ch == '+' || ch == '-' || ch == '/' || ch == '(' || ch == ')'
|
2017-06-19 08:06:54 +00:00
|
|
|
}
|
|
|
|
|
2019-12-31 21:57:54 +00:00
|
|
|
func processFields(fieldStr string) (fields []DBField) {
|
2022-02-21 03:32:53 +00:00
|
|
|
if fieldStr == "" {
|
|
|
|
return fields
|
|
|
|
}
|
|
|
|
var buffer string
|
|
|
|
var lastItem int
|
|
|
|
fieldStr += ","
|
|
|
|
for i := 0; i < len(fieldStr); i++ {
|
|
|
|
ch := fieldStr[i]
|
|
|
|
if ch == '(' {
|
|
|
|
i = skipFunctionCall(fieldStr, i-1)
|
|
|
|
fields = append(fields, DBField{Name: fieldStr[lastItem : i+1], Type: getIdentifierType(fieldStr[lastItem : i+1])})
|
|
|
|
buffer = ""
|
|
|
|
lastItem = i + 2
|
|
|
|
} else if ch == ',' && buffer != "" {
|
|
|
|
fields = append(fields, DBField{Name: buffer, Type: getIdentifierType(buffer)})
|
|
|
|
buffer = ""
|
|
|
|
lastItem = i + 1
|
|
|
|
} else if (ch >= 32) && ch != ',' && ch != ')' {
|
|
|
|
buffer += string(ch)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return fields
|
2017-06-12 09:03:14 +00:00
|
|
|
}
|
|
|
|
|
2020-01-01 01:26:15 +00:00
|
|
|
func getIdentifierType(iden string) int {
|
2022-02-21 03:32:53 +00:00
|
|
|
if ('a' <= iden[0] && iden[0] <= 'z') || ('A' <= iden[0] && iden[0] <= 'Z') {
|
|
|
|
if iden[len(iden)-1] == ')' {
|
|
|
|
return IdenFunc
|
|
|
|
}
|
|
|
|
return IdenColumn
|
|
|
|
}
|
|
|
|
if iden[0] == '\'' || iden[0] == '"' {
|
|
|
|
return IdenString
|
|
|
|
}
|
|
|
|
return IdenLiteral
|
2017-06-12 09:03:14 +00:00
|
|
|
}
|
|
|
|
|
2019-12-31 21:57:54 +00:00
|
|
|
func getIdentifier(seg string, startOffset int) (out string, i int) {
|
2022-02-21 03:32:53 +00:00
|
|
|
seg = strings.TrimSpace(seg)
|
|
|
|
seg += " " // Avoid overflow bugs with slicing
|
|
|
|
for i = startOffset; i < len(seg); i++ {
|
|
|
|
ch := seg[i]
|
|
|
|
if ch == '(' {
|
|
|
|
i = skipFunctionCall(seg, i)
|
|
|
|
return strings.TrimSpace(seg[startOffset:i]), (i - 1)
|
|
|
|
}
|
|
|
|
if (ch == ' ' || isOpByte(ch)) && i != startOffset {
|
|
|
|
return strings.TrimSpace(seg[startOffset:i]), (i - 1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return strings.TrimSpace(seg[startOffset:]), (i - 1)
|
2017-06-12 09:03:14 +00:00
|
|
|
}
|
|
|
|
|
2019-12-31 21:57:54 +00:00
|
|
|
func getOperator(seg string, startOffset int) (out string, i int) {
|
2022-02-21 03:32:53 +00:00
|
|
|
seg = strings.TrimSpace(seg)
|
|
|
|
seg += " " // Avoid overflow bugs with slicing
|
|
|
|
for i = startOffset; i < len(seg); i++ {
|
|
|
|
if !isOpByte(seg[i]) && i != startOffset {
|
|
|
|
return strings.TrimSpace(seg[startOffset:i]), (i - 1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return strings.TrimSpace(seg[startOffset:]), (i - 1)
|
2017-06-12 09:03:14 +00:00
|
|
|
}
|
|
|
|
|
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
|
|
|
func skipFunctionCall(data string, index int) int {
|
2022-02-21 03:32:53 +00:00
|
|
|
var braceCount int
|
|
|
|
for ; index < len(data); index++ {
|
|
|
|
char := data[index]
|
|
|
|
if char == '(' {
|
|
|
|
braceCount++
|
|
|
|
} else if char == ')' {
|
|
|
|
braceCount--
|
|
|
|
if braceCount == 0 {
|
|
|
|
return index
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return index
|
2017-06-12 09:03:14 +00:00
|
|
|
}
|
|
|
|
|
2020-01-14 05:07:00 +00:00
|
|
|
func writeFile(name, content string) (err error) {
|
2022-02-21 03:32:53 +00:00
|
|
|
f, err := os.Create(name)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
_, err = f.WriteString(content)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = f.Sync()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return f.Close()
|
2017-06-12 09:03:14 +00:00
|
|
|
}
|