Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 9ff0a6426574
Choose a base ref
...
head repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: ace078dd275f
Choose a head ref
  • 4 commits
  • 6 files changed
  • 1 contributor

Commits on Sep 30, 2021

  1. Copy the full SHA
    5a993d6 View commit details

Commits on Oct 1, 2021

  1. A nicer regexp.

    pleroy committed Oct 1, 2021
    Copy the full SHA
    10797b0 View commit details
  2. Code simplification.

    pleroy committed Oct 1, 2021
    Copy the full SHA
    237c2a3 View commit details
  3. Merge pull request #3130 from pleroy/2984

    Improve the parsing of time spans
    pleroy authored Oct 1, 2021
    Copy the full SHA
    ace078d View commit details
2 changes: 1 addition & 1 deletion Principia.sln
Original file line number Diff line number Diff line change
@@ -61,7 +61,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Legal", "Legal", "{4B25658F
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ksp_plugin_adapter", "ksp_plugin_adapter\ksp_plugin_adapter.csproj", "{E75B3F05-D64F-4AFE-9493-2F94A9B37510}"
ProjectSection(ProjectDependencies) = postProject
{873680B3-2406-4A30-9EE7-569E9B9DA661} = {873680B3-2406-4A30-9EE7-569E9B9DA661}
{A3F94607-2666-408F-AF98-0E47D61C98BB} = {A3F94607-2666-408F-AF98-0E47D61C98BB}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ksp_plugin", "ksp_plugin\ksp_plugin.vcxproj", "{A3F94607-2666-408F-AF98-0E47D61C98BB}"
1 change: 0 additions & 1 deletion ksp_plugin_adapter/burn_editor.cs
Original file line number Diff line number Diff line change
@@ -325,7 +325,6 @@ internal string FormatPreviousCoastDuration(double seconds) {
internal bool TryParsePreviousCoastDuration(string text, out double value) {
value = 0;
if (!PrincipiaTimeSpan.TryParse(text,
with_seconds: true,
out PrincipiaTimeSpan ts)) {
return false;
}
8 changes: 4 additions & 4 deletions ksp_plugin_adapter/differential_slider.cs
Original file line number Diff line number Diff line change
@@ -61,10 +61,10 @@ public double max_value {
public double value {
get => value_ ?? 0.0;
set {
if (!value_.HasValue || value_ != value) {
value_ = value;
formatted_value_ = formatter_(value_.Value);
}
value_ = value;
// Reformat systematically, even if the value has not changed numerically,
// as it may have been edited all the same (e.g., remove zeroes).
formatted_value_ = formatter_(value_.Value);
}
}

1 change: 0 additions & 1 deletion ksp_plugin_adapter/flight_planner.cs
Original file line number Diff line number Diff line change
@@ -506,7 +506,6 @@ internal string FormatPlanLength(double value) {
internal bool TryParsePlanLength(string text, out double value) {
value = 0;
if (!PrincipiaTimeSpan.TryParse(text,
with_seconds: true,
out PrincipiaTimeSpan ts)) {
return false;
}
1 change: 0 additions & 1 deletion ksp_plugin_adapter/orbit_analyser.cs
Original file line number Diff line number Diff line change
@@ -126,7 +126,6 @@ public static string FormatMissionDuration(double seconds) {
public static bool TryParseMissionDuration(string str, out double seconds) {
seconds = 0;
if (PrincipiaTimeSpan.TryParse(str,
with_seconds: false,
out PrincipiaTimeSpan ts)) {
seconds = ts.total_seconds;
return true;
29 changes: 14 additions & 15 deletions ksp_plugin_adapter/time_span.cs
Original file line number Diff line number Diff line change
@@ -90,30 +90,29 @@ public string FormatPositive(bool with_leading_zeroes, bool with_seconds) {
public double total_seconds => seconds_;

public static bool TryParse(string text,
bool with_seconds,
out PrincipiaTimeSpan time_span) {
time_span = new PrincipiaTimeSpan(double.NaN);
// Using a technology that is customarily used to parse HTML.
string pattern = @"^[+]?\s*(\d+)\s*" +
string pattern = @"^[+]?\s*(?:(?<days>\d+)\s*" +
day_symbol +
@"\s*(\d+)\s*h\s*(\d+)\s*min";
if (with_seconds) {
pattern += @"\s*([0-9.,']+)\s*s$";
} else {
pattern += @"$";
}
@"\s*)?" +
@"(?:(?<hours>\d+)\s*h\s*)?" +
@"(?:(?<minutes>\d+)\s*min\s*)?" +
@"(?:(?<seconds>[0-9.,']+)\s*s\s*)?$";
var regex = new Regex(pattern);
var match = regex.Match(text);
if (!match.Success) {
return false;
}
string days = match.Groups[1].Value;
string hours = match.Groups[2].Value;
string minutes = match.Groups[3].Value;
string seconds = "0";
if (with_seconds) {
seconds = match.Groups[4].Value;
}

var days_group = match.Groups["days"];
var hours_group = match.Groups["hours"];
var minutes_group = match.Groups["minutes"];
var seconds_group = match.Groups["seconds"];
string days = days_group.Success ? days_group.Value : "0";
string hours = hours_group.Success ? hours_group.Value : "0";
string minutes = minutes_group.Success ? minutes_group.Value : "0";
string seconds = seconds_group.Success ? seconds_group.Value : "0";
if (!int.TryParse(days, out int d) ||
!int.TryParse(hours, out int h) ||
!int.TryParse(minutes, out int min) ||