Skip to content

Commit

Permalink
Migrate to lang/regex lib
Browse files Browse the repository at this point in the history
  • Loading branch information
niveathika committed Nov 11, 2023
1 parent 398ab32 commit 68a1246
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
19 changes: 9 additions & 10 deletions dashboard/graph.bal
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import ballerina/io;
import ballerina/lang.array;
import ballerina/log;
import ballerina/regex;
import thisarug/prettify;

type List record {|
Expand Down Expand Up @@ -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};

Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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 = [];

Expand All @@ -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;
}
Expand Down Expand Up @@ -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};
Expand All @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions dashboard/utils.bal
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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";
}
Expand Down

0 comments on commit 68a1246

Please sign in to comment.