Skip to content

Commit

Permalink
change most snake_case to camelCase; fix bugs
Browse files Browse the repository at this point in the history
1. This change only affects the code base, not the public API:
    changed almost all snake_case variable names to camelCase.
    RemesPath functions still use snake_case
    (e.g. `s_csv` and `s_mul` still have those names),
    and all the settings in Settings.cs
    that were previously snake_case
    (e.g. `auto_validate`, `use_npp_styling`) are still snake_case.
2. Fix a potential bug associated with calling
    FileInfo.OpenRead().ReadToEnd(),
    when the correct usage is instead to write
    using (var fp = fileInfo.OpenRead())
        { string s = fp.ReadToEnd(); }
    so that the StreamReader is correctly disposed.
3. Fix potential issue with restyling LinkLabels when
    going from a dark theme to a light theme (like default stylers.xml).
  • Loading branch information
molsonkiko committed Jan 15, 2024
1 parent 1eee576 commit 463322e
Show file tree
Hide file tree
Showing 36 changed files with 1,918 additions and 1,915 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1. The [`ifelse` vectorized function in RemesPath](/docs/RemesPath.md#vectorized-functions) now uses conditional execution.
2. Add optional arguments [to `stringify` non-vectorized function in RemesPath](/docs/RemesPath.md#non-vectorized-functions), so that users can control the format of the output.
3. Make dark mode icons darker.
4. __This change only affects the code base, not the public API:__ changed almost all snake_case variable names to camelCase. [RemesPath functions still use snake_case](/JsonToolsNppPlugin/JSONTools/RemesPathFunctions.cs) (e.g., `s_mul` and `group_by` still have those names), and all the settings in [Settings.cs](/JsonToolsNppPlugin/Utils/Settings.cs) (e.g., `use_npp_styling`) that were previously snake_case are still snake_case.

### Fixed

Expand Down
4 changes: 2 additions & 2 deletions JsonToolsNppPlugin/Forms/AboutForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ public AboutForm()
/// </summary>
private void GitHubLink_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
string help_url = "https://github.com/molsonkiko/JsonToolsNppPlugin";
string helpUrl = "https://github.com/molsonkiko/JsonToolsNppPlugin";
try
{
var ps = new ProcessStartInfo(help_url)
var ps = new ProcessStartInfo(helpUrl)
{
UseShellExecute = true,
Verb = "open"
Expand Down
48 changes: 24 additions & 24 deletions JsonToolsNppPlugin/Forms/FindReplaceForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,15 @@ private void AssignFindReplaceQueries()
findQuery = $"({root}).*[is_num(@)][@ {FindTextBox.Text}]";
return;
}
string keys_find_text;
string values_find_text;
string keysFindText;
string valuesFindText;
if (RegexBox.Checked)
{
if (IgnoreCaseCheckBox.Checked)
keys_find_text = "g`(?i)" + FindTextBox.Text.Replace("`", "\\`") + '`';
keysFindText = "g`(?i)" + FindTextBox.Text.Replace("`", "\\`") + '`';
else
keys_find_text = "g`" + FindTextBox.Text.Replace("`", "\\`") + '`';
values_find_text = $"[str(@) =~ {keys_find_text}]";
keysFindText = "g`" + FindTextBox.Text.Replace("`", "\\`") + '`';
valuesFindText = $"[str(@) =~ {keysFindText}]";
}
else if (MatchExactlyBox.Checked)
{
Expand All @@ -165,14 +165,14 @@ private void AssignFindReplaceQueries()
// exact matching is equivalent to regex matching
// with all special metacharacters escaped and anchors at the beginning and end
// add the (?i) flag for case-insensitive matching
keys_find_text = "g`(?i)^" + Regex.Escape(FindTextBox.Text).Replace("\\", "\\\\").Replace("`", "\\`") + "$`";
values_find_text = $"[str(@) =~ {keys_find_text}]";
keysFindText = "g`(?i)^" + Regex.Escape(FindTextBox.Text).Replace("\\", "\\\\").Replace("`", "\\`") + "$`";
valuesFindText = $"[str(@) =~ {keysFindText}]";
}
else
{
// simplest case; do normal hash map key search, or check if string equals find text exactly
keys_find_text = "`" + FindTextBox.Text.Replace("`", "\\`") + "`";
values_find_text = $"[str(@) == {keys_find_text}]";
keysFindText = "`" + FindTextBox.Text.Replace("`", "\\`") + "`";
valuesFindText = $"[str(@) == {keysFindText}]";
}
}
else
Expand All @@ -182,30 +182,30 @@ private void AssignFindReplaceQueries()
if (IgnoreCaseCheckBox.Checked)
{
// add the (?i) flag for case-insensitive matching
keys_find_text = "g`(?i)" + Regex.Escape(FindTextBox.Text).Replace("\\", "\\\\").Replace("`", "\\`") + "`";
values_find_text = $"[str(@) =~ {keys_find_text}]";
keysFindText = "g`(?i)" + Regex.Escape(FindTextBox.Text).Replace("\\", "\\\\").Replace("`", "\\`") + "`";
valuesFindText = $"[str(@) =~ {keysFindText}]";
}
else
{
keys_find_text = "g`" + Regex.Escape(FindTextBox.Text).Replace("\\", "\\\\").Replace("`", "\\`") + "`";
values_find_text = $"[str(@) =~ {keys_find_text}]";
keysFindText = "g`" + Regex.Escape(FindTextBox.Text).Replace("\\", "\\\\").Replace("`", "\\`") + "`";
valuesFindText = $"[str(@) =~ {keysFindText}]";
}
}
replaceQuery = $"s_sub(@, {keys_find_text}, `" + ReplaceTextBox.Text.Replace("`", "\\`") + "`)";
replaceQuery = $"s_sub(@, {keysFindText}, `" + ReplaceTextBox.Text.Replace("`", "\\`") + "`)";
if (RecursiveSearchBox.Checked)
{
switch (KeysValsBothBox.SelectedIndex)
{
case 0: // keys
findQuery = $"({root})..{keys_find_text}";
findQuery = $"({root})..{keysFindText}";
break;
case 1: // values
findQuery = $"({root})..*{values_find_text}";
findQuery = $"({root})..*{valuesFindText}";
break;
default: // both keys and values
findQuery = "concat(\r\n" +
$" ({root})..{keys_find_text},\r\n" +
$" ({root})..*{values_find_text}\r\n" +
$" ({root})..{keysFindText},\r\n" +
$" ({root})..*{valuesFindText}\r\n" +
$")";
break;
}
Expand All @@ -214,15 +214,15 @@ private void AssignFindReplaceQueries()
switch (KeysValsBothBox.SelectedIndex)
{
case 0: // keys
findQuery = $"({root}).{keys_find_text}";
findQuery = $"({root}).{keysFindText}";
break;
case 1: // values
findQuery = $"{root}{values_find_text}";
findQuery = $"{root}{valuesFindText}";
break;
default: // both keys and values
findQuery = "concat(\r\n" +
$" ({root}).{keys_find_text},\r\n" +
$" {root}{values_find_text}\r\n" +
$" ({root}).{keysFindText},\r\n" +
$" {root}{valuesFindText}\r\n" +
$")";
break;
}
Expand All @@ -239,7 +239,7 @@ private void FindButton_Click(object sender, EventArgs e)

private void ReplaceButton_Click(object sender, EventArgs e)
{
int keysvals_index = KeysValsBothBox.SelectedIndex;
int keysvalsIndex = KeysValsBothBox.SelectedIndex;
KeysValsBothBox.SelectedIndex = 1;
AssignFindReplaceQueries();
string root = (RecursiveSearchBox.Checked) ? $"(@{RootTextBox.Text})..*" : $"@{RootTextBox.Text}";
Expand All @@ -255,7 +255,7 @@ private void ReplaceButton_Click(object sender, EventArgs e)
// and (2) it displays exactly the values that were mutated rather than forcing the user to find them
treeViewer.SubmitQueryButton.PerformClick();
treeViewer.Tree.Nodes[0].Expand();
KeysValsBothBox.SelectedIndex = keysvals_index;
KeysValsBothBox.SelectedIndex = keysvalsIndex;
}

private void SwapFindReplaceButton_Click(object sender, EventArgs e)
Expand Down
Loading

0 comments on commit 463322e

Please sign in to comment.