From 68a12468a95046092fcb5aba2654c0c721b705cb Mon Sep 17 00:00:00 2001 From: Niveathika Date: Sat, 11 Nov 2023 14:55:28 +0530 Subject: [PATCH] Migrate to lang/regex lib --- dashboard/graph.bal | 19 +++++++++---------- dashboard/utils.bal | 3 +-- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/dashboard/graph.bal b/dashboard/graph.bal index fd484cec..127ecb75 100644 --- a/dashboard/graph.bal +++ b/dashboard/graph.bal @@ -17,7 +17,6 @@ import ballerina/io; import ballerina/lang.array; import ballerina/log; -import ballerina/regex; import thisarug/prettify; type List record {| @@ -54,7 +53,7 @@ function getSortedModuleNameList() returns List|error { List nameList = check nameListJson.cloneWithType(); Module[] sortedModules = from var e in nameList.modules - order by regex:split(e.name, "-")[2] ascending + order by re `-`.split(e.name)[2] ascending select e; List sortedNameList = {modules: sortedModules}; @@ -98,11 +97,11 @@ function initializeModuleInfo(Module module) returns Module|error { } function getVersion(string moduleName, string gradleProperties) returns string|error { - string[] gradlePropertiesLines = regex:split(gradleProperties, "\n"); + string[] gradlePropertiesLines = re `\n`.split(gradleProperties); string moduleVersion = ""; foreach var line in gradlePropertiesLines { if line.startsWith("version") { - moduleVersion = regex:split(line, "=")[1]; + moduleVersion = re `=`.split(line)[1]; break; } } @@ -136,7 +135,7 @@ function getDependencies(Module module, List moduleDetails) returns string[]|err string moduleName = module.name; string? propertiesFile = module.gradle_properties; if propertiesFile is string { - propertiesFileArr = regex:split(propertiesFile, "\n"); + propertiesFileArr = re `\n`.split(propertiesFile); } string[] dependencies = []; @@ -147,7 +146,7 @@ function getDependencies(Module module, List moduleDetails) returns string[]|err continue; } string? versionKey = item.version_key; - if versionKey is string && regex:matches(line, "^.*" + versionKey + ".*$") { + if versionKey is string && re `^.*${versionKey}.*$`.isFullMatch(line) { dependencies.push(dependentName); break; } @@ -246,11 +245,11 @@ function removeModulesInIntermediatePaths(DiGraph dependencyGraph, string source function seperateModules(List moduleDetails) returns List[] { Module[] ballerinaxSorted = from var e in moduleDetails.modules - where regex:split(e.name, "-")[1] == "ballerinax" + where re `-`.split(e.name)[1] == "ballerinax" order by e.level ascending select e; Module[] ballerinaSorted = from var e in moduleDetails.modules - where regex:split(e.name, "-")[1] == "ballerina" + where re `-`.split(e.name)[1] == "ballerina" order by e.level ascending select e; List sortedNameListX = {modules: ballerinaxSorted}; @@ -261,11 +260,11 @@ function seperateModules(List moduleDetails) returns List[] { // Updates the stdlib dashboard in README.md function updateStdlibDashboard(List moduleDetailsBalX, List moduleDetailsBal) returns error? { - string[] readmeFile = regex:split(check io:fileReadString(README_FILE), "\n"); + string[] readmeFile = re `\n`.split(check io:fileReadString(README_FILE)); string updatedReadmeFile = ""; foreach string line in readmeFile { updatedReadmeFile += line + "\n"; - if regex:matches(line, "^.*" + DASHBOARD_TITLE + ".*$") { + if re `^.*${DASHBOARD_TITLE}.*$`.isFullMatch(line) { updatedReadmeFile += "\n" + BAL_TITLE + "\n"; updatedReadmeFile += README_HEADER; updatedReadmeFile += README_HEADER_SEPARATOR; diff --git a/dashboard/utils.bal b/dashboard/utils.bal index 22ce0cb1..30b0e58e 100644 --- a/dashboard/utils.bal +++ b/dashboard/utils.bal @@ -15,7 +15,6 @@ // under the License. import ballerina/http; -import ballerina/regex; import ballerina/url; function getDashboardRow(Module module, string level) returns string|error { @@ -153,7 +152,7 @@ function getBalTestNativeBadge(string moduleName, string defaultBranch) returns } function getModuleShortName(string moduleName) returns string { - string shortName = regex:split(moduleName, "-")[2]; + string shortName = re `-`.split(moduleName)[2]; if shortName == "jballerina.java.arrays" { return "java.arrays"; }