-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtoOneLineStringController.js
More file actions
76 lines (66 loc) · 2.07 KB
/
toOneLineStringController.js
File metadata and controls
76 lines (66 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
app.controller("toOneLineStringController", function ($scope) {
$scope.checks = {
toOneLine : true,
tabSpaces : true,
trim : true,
toLowerCase : false,
toUpperCase : false
}
/* $scope.typesToReplace = [
{typeConcat : "new line", symbol : "\n"},
{typeConcat : "semicolon", symbol : ";"},
{typeConcat : "dash", symbol : "-"},
{typeConcat : "underscore", symbol : "_"},
];*/
$scope.stringIn = "";
$scope.stringOut = undefined;
$scope.replaceIn = "";
$scope.replaceOut = "";
$scope.msgError = undefined;
$scope.UpdateCheckBox = function(name){
if(name == "toLowerCase" && $scope.checks.toUpperCase == true){
$scope.checks.toUpperCase = false;
}
if(name == "toUpperCase" && $scope.checks.toLowerCase == true){
$scope.checks.toLowerCase = false;
}
}
$scope.replaceString = function(){
try{
$scope.msgError = undefined;
$scope.stringOut = undefined;
var localStringIn = $scope.stringToReplace;
if(localStringIn != ""){
if($scope.checks.trim == true){
localStringIn = $scope.stringToReplace.trim();
}
if($scope.checks.toOneLine == true){
localStringIn = localStringIn.replace(/(?:\r\n|\r|\n)/g, '');
}
if($scope.checks.tabSpaces == true){
localStringIn = localStringIn.replace(/\t/g,"");
}
if($scope.checks.toLowerCase == true){
localStringIn = localStringIn.toLowerCase();
}
if($scope.checks.toUpperCase == true){
localStringIn = localStringIn.toUpperCase();
}
if($scope.replaceIn != "" && $scope.replaceOut != ""){
var replace = new RegExp($scope.replaceIn,"g");
localStringIn = localStringIn.replace(replace,$scope.replaceOut);
}
else if($scope.replaceIn != ""){
var replace = new RegExp($scope.replaceIn,"g");
localStringIn = localStringIn.replace(replace,$scope.replaceOut);
}
$scope.stringOut = localStringIn;
}else{
$scope.msgError = "You must insert elements in both text boxes";
}
}
catch(err){
$scope.msgError = err.toString();
}
}
});