mirror of
https://gitlab.com/MrFry/moodle-test-userscript
synced 2025-04-01 20:22:48 +02:00
Removing special characters from strings, and replacig fixes
This commit is contained in:
parent
b647007337
commit
5b8ee3fbb8
1 changed files with 15 additions and 5 deletions
20
main.js
20
main.js
|
@ -83,7 +83,7 @@ class StringUtils {
|
|||
var toremove = this.NormalizeSpaces(val)
|
||||
|
||||
var regex = new RegExp(char, 'g')
|
||||
toremove.replace(regex, ' ')
|
||||
toremove = toremove.replace(regex, ' ')
|
||||
|
||||
return this.RemoveUnnecesarySpaces(toremove)
|
||||
}
|
||||
|
@ -107,11 +107,21 @@ class StringUtils {
|
|||
var removableChars = [',', '.', ':', '!']
|
||||
for (var i = 0; i < removableChars.length; i++) {
|
||||
var regex = new RegExp(removableChars[i], 'g')
|
||||
value.replace(regex, '')
|
||||
value = value.replace(regex, '')
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
RemoveSpecialChars (value) {
|
||||
assert(value)
|
||||
|
||||
let removableChars = ['&']
|
||||
return removableChars.reduce((res, x) => {
|
||||
let regex = new RegExp(x, 'g')
|
||||
return res.replace(regex, '')
|
||||
}, value)
|
||||
}
|
||||
|
||||
// if the value is empty, or whitespace
|
||||
EmptyOrWhiteSpace (value) {
|
||||
// replaces /n-s with "". then replaces spaces with "". if it equals "", then its empty, or only consists of white space
|
||||
|
@ -146,9 +156,9 @@ class StringUtils {
|
|||
|
||||
class Question {
|
||||
constructor (q, a, i) {
|
||||
this.Q = q
|
||||
this.A = a
|
||||
this.I = i
|
||||
this.Q = SUtils.RemoveSpecialChars(q)
|
||||
this.A = SUtils.RemoveSpecialChars(a)
|
||||
this.I = SUtils.RemoveSpecialChars(i)
|
||||
}
|
||||
|
||||
toString () {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue