aboutsummaryrefslogtreecommitdiffhomepage
path: root/frontend/app/states/watch.ts
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/app/states/watch.ts')
-rw-r--r--frontend/app/states/watch.ts24
1 files changed, 18 insertions, 6 deletions
diff --git a/frontend/app/states/watch.ts b/frontend/app/states/watch.ts
index 2c255f4..50fa425 100644
--- a/frontend/app/states/watch.ts
+++ b/frontend/app/states/watch.ts
@@ -1,5 +1,6 @@
import { atom } from "jotai";
import type { components } from "../api/schema";
+import type { SupportedLanguage } from "../types/SupportedLanguage";
const gameStartedAtAtom = atom<number | null>(null);
export const setGameStartedAtAtom = atom(null, (_, set, value: number | null) =>
@@ -84,12 +85,23 @@ export const setLatestGameStatesAtom = atom(
},
);
-export function calcCodeSize(code: string): number {
- const trimmed = code
- .replace(/\s+/g, "")
- .replace(/^<\?php/, "")
- .replace(/^<\?/, "")
- .replace(/\?>$/, "");
+function cleanCode(code: string, language: SupportedLanguage) {
+ if (language === "php") {
+ return code
+ .replace(/\s+/g, "")
+ .replace(/^<\?php/, "")
+ .replace(/^<\?/, "")
+ .replace(/\?>$/, "");
+ } else {
+ return code.replace(/\s+/g, "");
+ }
+}
+
+export function calcCodeSize(
+ code: string,
+ language: SupportedLanguage,
+): number {
+ const trimmed = cleanCode(code, language);
const utf8Encoded = new TextEncoder().encode(trimmed);
return utf8Encoded.length;
}