Adding RegEx input checks and removing license #40
-21
@@ -1,21 +0,0 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024 Marcel Pöppe
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -47,7 +47,8 @@ ToDo
|
||||
4. Push your branch: `git push origin featurename`
|
||||
5. Create a pull request
|
||||
# Licence
|
||||
This project is licensed under the [MIT License](https://github.com/Spaceholder-Programming/Operations-Research-Tool?tab=MIT-1-ov-file).
|
||||
For further information, please check out the [LICENSE](https://github.com/Spaceholder-Programming/Operations-Research-Tool/blob/main/LICENCE.txt).
|
||||
=======
|
||||
# Contact
|
||||
If you have the desire to contact the team behind this project, use the contact details on our GitHub accounts:
|
||||
+ [bRNS98](https://github.com/bRNS98)
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 3.2 KiB |
+2
-2
@@ -15,8 +15,8 @@ const geistMono = localFont({
|
||||
});
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "Create Next App",
|
||||
description: "Generated by create next app",
|
||||
title: "OR-Tool by Spaceholder Programming",
|
||||
description: "OR-Tool by Spaceholder Programming",
|
||||
};
|
||||
|
||||
export default function RootLayout({
|
||||
|
||||
+5
-5
@@ -19,19 +19,19 @@ export default function Home() {
|
||||
</header>
|
||||
<Box
|
||||
title={"Objective"}
|
||||
placeholder={"Objective"}
|
||||
placeholder={"Insert your objective here. One objective is allowed. Use one line for it (no \"return\"!) Allowed symbols are 0-9, a-z, A-Z and <>=.\nExample:\nx + y\n-786433 x1 + 655361 x2"}
|
||||
id="objective"/>
|
||||
<Box
|
||||
title={"Subject"}
|
||||
placeholder={"Subject"}
|
||||
placeholder={"Insert your subject here. One per line (divide by 'return' button). Allowed symbols are 0-9, a-z, A-Z and <>=.\nExample:\n+1 x + 2 y <= 15\n524321 x14 + 524305 x15 <= 4194303.5"}
|
||||
id="subject"/>
|
||||
<Box
|
||||
title={"Bounds"}
|
||||
placeholder={"Bounds"}
|
||||
placeholder={"Insert your bounds here. One per line (divide by 'return' button). Allowed symbols are 0-9, a-z, A-Z and <>=.\nExample:\nx >= 0\nx > 0\n0 <= x1 <= 1"}
|
||||
id="bounds"/>
|
||||
<Box
|
||||
title={"Variables"}
|
||||
placeholder={"Your Variables here"}
|
||||
placeholder={"List all your variables. One per line (divide by 'return' button). Allowed symbols are a-z, A-Z.\nExample:\nx\ny"}
|
||||
id="vars" />
|
||||
<Button
|
||||
title={"Calculate"}
|
||||
@@ -47,7 +47,7 @@ export default function Home() {
|
||||
<br></br>
|
||||
<Output
|
||||
id="out"
|
||||
text={"Ergebnis"}/>
|
||||
text={"Input a problem and an action button to display output..."}/>
|
||||
{/* <Popup_Button
|
||||
title="Popup"
|
||||
className="button"
|
||||
|
||||
@@ -46,6 +46,52 @@ function walltimeStart() {
|
||||
return Date.now();
|
||||
}
|
||||
|
||||
function isInputValidRegex(obj: string | undefined, subj: string | undefined, bounds: string | undefined, vars: string | undefined): boolean {
|
||||
customLog("Staring input checks...");
|
||||
|
||||
// standard case: input is undefined - invalid
|
||||
if (obj === undefined || obj === null || subj === undefined || subj === null || bounds === undefined || bounds === null || vars === undefined || vars === null) {
|
||||
customLog("Error: Function isInputValidRegex received undefined or null input.");
|
||||
return false;
|
||||
}
|
||||
|
||||
// RegEx check for objective
|
||||
let regex = /^[ (\n)]*[\+-]? *((\d+(.\d+)? )?[a-zA-Z][a-zA-Z0-9]*)( *[\+-] *((\d+(.\d+)? )?[a-zA-Z][a-zA-Z0-9]*))*[ (\n)]*$/g;
|
||||
let isValid = regex.test(obj);
|
||||
if (!isValid) {
|
||||
customLog("Error: Invalid or missing character in object box.");
|
||||
return false;
|
||||
}
|
||||
|
||||
// RegEx check for subject
|
||||
regex = /^([ (\n)]*[\+-]* *(\d+(.\d+)? )?[a-zA-Z][a-zA-Z0-9]*( *[\+-] *(\d+(.\d+)? )?[a-zA-Z][a-zA-Z0-9]*)* *((<=?)|(>=?)|=) *[\+-]? *\d+(.\d+)?[ (\n)]*)+$/g;
|
||||
isValid = regex.test(subj);
|
||||
if (!isValid) {
|
||||
customLog("Error: Invalid or missing character in subject box.");
|
||||
return false;
|
||||
}
|
||||
|
||||
// RegEx check for subject
|
||||
regex = /[ (\n)]*(([a-zA-Z][a-zA-Z0-9]* *((<=?)|(>=?)|=) *\d(.\d+)?)|((\d(.\d+)?) *<=? *[a-zA-Z][a-zA-Z0-9]* *<= *(\d(.\d+)?)))[ (\n)]*/g;
|
||||
isValid = regex.test(bounds);
|
||||
if (!isValid) {
|
||||
customLog("Error: Invalid or missing character in bounds box.");
|
||||
return false;
|
||||
}
|
||||
|
||||
// RegEx check for variables
|
||||
regex = /^ *([a-zA-Z][a-zA-Z0-9]*(\n)* *)+$/g;
|
||||
isValid = regex.test(vars);
|
||||
if (!isValid) {
|
||||
customLog("Error: Invalid or missing character in variables box.");
|
||||
return false;
|
||||
}
|
||||
|
||||
customLog("All input checks successful.");
|
||||
customLog("");
|
||||
return true;
|
||||
}
|
||||
|
||||
function isInputFilled(obj: string | undefined, subj: string | undefined, bounds: string | undefined, vars: string | undefined) {
|
||||
if (obj == "" || obj == null || obj == undefined) {
|
||||
customLog("Error: Empty input field.");
|
||||
@@ -148,6 +194,9 @@ export function calculate_click() {
|
||||
// catch error: empty input field(s)
|
||||
if (!isInputFilled(objective, subject, bounds, variables)) return;
|
||||
|
||||
// catch error: variables field has invalid characters
|
||||
if (!isInputValidRegex(objective, subject, bounds, variables)) return;
|
||||
|
||||
let wholeText: string = "Maximize\n obj: " + objective
|
||||
+ "\nSubject To \n" + subject
|
||||
+ "\nBounds \n" + bounds
|
||||
|
||||
Reference in New Issue
Block a user