Skip to content

Commit

Permalink
style: convert to standard Octave format
Browse files Browse the repository at this point in the history
* convert full-line % comments to #
* convert ~ negations to !
* convert generic 'end's to specific 'end<x>'s
* trim trailing whitespace
* add an .editorconfig

Does not do "(...)" around if/while/for predicates.
  • Loading branch information
apjanke committed Feb 2, 2024
1 parent 5e84f61 commit 464fc07
Show file tree
Hide file tree
Showing 201 changed files with 6,125 additions and 6,100 deletions.
20 changes: 20 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# EditorConfig for Tablicious
#
# This is set up to conform to standard GNU Octave code style, to the extent that
# EditorConfig supports that.
#
# See: https://wiki.octave.org/Octave_style_guide

root = true

[*]
insert_final_newline = true
charset = utf-8
indent_style = space
trim_trailing_whitespace = true

[*.m]
indent_size = 2

[*.cc]
indent_size = 2
78 changes: 39 additions & 39 deletions inst/+tblish/+chrono/+internal/+algo/binsearch.m
Original file line number Diff line number Diff line change
@@ -1,52 +1,52 @@
function [tf, loc] = binsearch (needles, haystack)
%BINSEARCH Binary search
%
% [tf, loc] = binsearch (needles, haystack)
%
% Searches for needles in haystack. Needles and haystack must both be doubles.
% Haystack must be a sorted vector. (The sortedness is not checked, for speed:
% if it is not sorted, you will just get wrong answers instead of raising an
% error.
%
% This does the same thing as ismember(), but is faster for large inputs, with
% an additional restriction that the array to search through must be sorted.
%
% The input type must have a total ordering over the values present in needles
% and haystack. That means you can't pass in NaNs or anything that behaves
% like them.
%
% Returns arrays the same size as needles. tf is a logical array indicating
% whether each element was found. loc is an array of indexes, either where it
% was found, or if not found, -1 * the index of the element where it should be
% inserted; that is, the index of the first element larger than it, or one past
% the end of the array if it is larger than all the elements in the haystack.
if ~isvector (haystack) && ~isempty (haystack)
#BINSEARCH Binary search
#
# [tf, loc] = binsearch (needles, haystack)
#
# Searches for needles in haystack. Needles and haystack must both be doubles.
# Haystack must be a sorted vector. (The sortedness is not checked, for speed:
# if it is not sorted, you will just get wrong answers instead of raising an
# error.
#
# This does the same thing as ismember(), but is faster for large inputs, with
# an additional restriction that the array to search through must be sorted.
#
# The input type must have a total ordering over the values present in needles
# and haystack. That means you can't pass in NaNs or anything that behaves
# like them.
#
# Returns arrays the same size as needles. tf is a logical array indicating
# whether each element was found. loc is an array of indexes, either where it
# was found, or if not found, -1 * the index of the element where it should be
# inserted; that is, the index of the first element larger than it, or one past
# the end of the array if it is larger than all the elements in the haystack.

if !isvector (haystack) && !isempty (haystack)
error ('haystack must be a vector or empty');
end
if ~isequal (class (needles), class (haystack))
endif
if !isequal (class (needles), class (haystack))
error ('needles and haystack must be same type; got %s and %s', ...
class (needles), class (haystack));
end
% Use exact type test to avoid false-positives from objects overriding isnumeric()
endif

# Use exact type test to avoid false-positives from objects overriding isnumeric()
numeric_types = {'double' 'single' 'int8' 'int16' 'int32' 'int64' ...
'uint8' 'uint16' 'uint32' 'uint64'};
is_numeric = ismember (class (needles), numeric_types);

if is_numeric
if iscomplex (needles) || iscomplex (haystack)
error ('Complex values are not supported');
end
endif
loc = double (__tblish_time_binsearch__ (needles, haystack));
else
loc = binsearch_mcode (needles, haystack);
end
endif
tf = loc > 0;
end
endfunction

function out = binsearch_mcode (vals, arr)
%BINSEARCH_MCODE Native M-code implementation of binsearch
#BINSEARCH_MCODE Native M-code implementation of binsearch
out = NaN (size (vals));
for i_val = 1:numel (vals)
val = vals(i_val);
Expand All @@ -65,10 +65,10 @@
break;
else
error('Total ordering violation: neither <, >, nor == was true for this value.');
end
end
if ~found
endif
endwhile
if !found
out(i) = -1 * low;
end
end
end
endif
endfor
endfunction
12 changes: 6 additions & 6 deletions inst/+tblish/+chrono/+internal/+tzinfo/PosixZoneRule.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
classdef PosixZoneRule
%POSIXZONERULE A POSIX-style time zone rule
#POSIXZONERULE A POSIX-style time zone rule

properties
local_timezone
std_name
Expand All @@ -9,11 +9,11 @@
dst_start_rule
dst_end_rule
endproperties

methods (Static)
function out = parseZoneRule (str)
out = tblish.chrono.internal.algo.PosixZoneRule;
if ~isrow (in)
if !isrow (in)
error ('in must be charvec; got non-row char');
endif
els = strsplit (in, ',');
Expand Down Expand Up @@ -43,11 +43,11 @@
this = tblish.chrono.internal.tzinfo.PosixZoneRule.parseZoneRule(in);
endif
endfunction

function out = gmtToLocalDatenum (this, dnums)
error ('Unimplemented');
endfunction

function out = localToGmtDatenum (this, dnums, isDst)
error ('Unimplemented');
endfunction
Expand Down
124 changes: 62 additions & 62 deletions inst/+tblish/+chrono/+internal/+tzinfo/TzDb.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@
## <https://www.gnu.org/licenses/>.

classdef TzDb
%TZDB Interface to the tzinfo database
%
% This class is an interface to the tzinfo database (AKA the Olson database)
#TZDB Interface to the tzinfo database
#
# This class is an interface to the tzinfo database (AKA the Olson database)

properties
% Path to the zoneinfo directory
# Path to the zoneinfo directory
path
endproperties

methods (Static)
function out = instance ()
%INSTANCE Shared global instance of TzDb
#INSTANCE Shared global instance of TzDb
persistent value
if isempty (value)
value = tblish.chrono.internal.tzinfo.TzDb;
Expand All @@ -39,55 +39,55 @@

methods
function this = TzDb (path)
%TZDB Construct a new TzDb object
%
% this = TzDb (path)
%
% path (char) is the path to the tzinfo database directory. If omitted or
% empty, it defaults to the default path ('/usr/share/zoneinfo' on Unix,
% and an error on Windows).
#TZDB Construct a new TzDb object
#
# this = TzDb (path)
#
# path (char) is the path to the tzinfo database directory. If omitted or
# empty, it defaults to the default path ('/usr/share/zoneinfo' on Unix,
# and an error on Windows).
if nargin < 1; path = []; endif
if isempty (path)
this.path = tblish.chrono.internal.tzinfo.TzDb.defaultPath;
else
this.path = path;
endif
endfunction

function out = dbVersion (this)
%DBVERSION Version of the zoneinfo database this is reading
%
% out = dbVersion (this)
%
% Returns the zoneinfo database version as a string.
#DBVERSION Version of the zoneinfo database this is reading
#
# out = dbVersion (this)
#
# Returns the zoneinfo database version as a string.
versionFile = [this.path '/+VERSION'];
txt = tblish.chrono.internal.slurpTextFile (versionFile);
out = strtrim (txt);
endfunction

function out = zoneTab (this)
%ZONETAB Get the zone definition table
%
% This lists the metadata from the "zone.tab" file included in the
% zoneinfo database.
%
% Returns a struct with fields:
% CountryCode
% Coordinates
% TZ
% Comments
% Each of which contains a cellstr column vector.
#ZONETAB Get the zone definition table
#
# This lists the metadata from the "zone.tab" file included in the
# zoneinfo database.
#
# Returns a struct with fields:
# CountryCode
# Coordinates
# TZ
# Comments
# Each of which contains a cellstr column vector.
persistent data
if isempty (data)
data = this.readZoneTab;
endif
out = data;
endfunction

function out = definedZones (this)
%DEFINEDZONES List defined zone IDs
%
% out = definedZones (this)
#DEFINEDZONES List defined zone IDs
#
# out = definedZones (this)
persistent value
if isempty (value)
specialFiles = {'+VERSION', 'iso3166.tab', 'zone.tab', 'posixrules'};
Expand All @@ -99,20 +99,20 @@
endif
out = value;
endfunction

function out = zoneDefinition (this, zoneId)
%ZONEDEFINITION Get the time zone definition for a given time zone
%
% out = zoneDefinition (this, zoneId)
%
% zoneId (char) is the time zone identifier in IANA format. For example,
% 'UTC' or 'America/New_York'.
%
% Returns the zone definition as an object. (This is currently under
% construction; it now returns a placeholder struct.)
#ZONEDEFINITION Get the time zone definition for a given time zone
#
# out = zoneDefinition (this, zoneId)
#
# zoneId (char) is the time zone identifier in IANA format. For example,
# 'UTC' or 'America/New_York'.
#
# Returns the zone definition as an object. (This is currently under
# construction; it now returns a placeholder struct.)
s = this.readZoneFile (zoneId);

% We prefer the version 2 stuff
# We prefer the version 2 stuff
out = tblish.chrono.internal.tzinfo.TzInfo;
if isfield (s, 'section2')
defn_s = s.section2;
Expand All @@ -125,15 +125,15 @@
out = calculateDerivedData (out);
endfunction
endmethods

methods (Access = private)
function out = readZoneTab (this)
%READZONETAB Actually read and parse the zonetab file
% Use the "deprecated" plain zone.tab because zone1970.tab is not present
% on all systems.
#READZONETAB Actually read and parse the zonetab file

# Use the "deprecated" plain zone.tab because zone1970.tab is not present
# on all systems.
zoneTabFile = [this.path '/zone.tab'];

txt = tblish.chrono.internal.slurpTextFile (zoneTabFile);
lines = strsplit (txt, sprintf('\n'));
starts = regexp (lines, '^\s*#|^\s*$', 'start', 'once');
Expand All @@ -144,23 +144,23 @@
pattern = '^(\w+)\s+(\S+)\s+(\S+)\s*(.*)';
[match,tok] = regexp (lines, pattern, 'match', 'tokens');
tfMatch = ~cellfun ('isempty', match);
if ~all (tfMatch)
ixBad = find (~tfMatch);
if !all (tfMatch)
ixBad = find (!tfMatch);
error ('Failed parsing line in zone.tab file: "%s"', lines{ixBad(1)});
endif
tok = cat (1, tok{:});
tok = cat (1, tok{:});

out = struct;
out.CountryCode = tok(:,1);
out.Coordinates = tok(:,2);
out.TZ = tok(:,3);
out.Comments = tok(:,4);
endfunction

function out = readZoneFile (this, zoneId)
%READZONEFILE Read and parse a zone definition file
if ~ismember (zoneId, this.definedZones)
#READZONEFILE Read and parse a zone definition file
if !ismember (zoneId, this.definedZones)
error ("Undefined time zone: '%s'", zoneId);
endif
zoneFile = [this.path '/' zoneId];
Expand All @@ -173,7 +173,7 @@
tzZoneFile = tblish.chrono.internal.tzinfo.TzZoneFile (zoneFile);
out = tzZoneFile.readZoneFile ();
endfunction

function [out, n_bytes_read] = parseZoneSection(this, data, sectionFormat)
parser = tblish.chrono.internal.tzinfo.ZoneFileSectionParser;
parser.data = data;
Expand All @@ -186,8 +186,8 @@
methods (Static)
function out = defaultPath ()
if ispc
% Use the zoneinfo database bundled with Tablicious, because Windows doesn't
% supply one.
# Use the zoneinfo database bundled with Tablicious, because Windows doesn't
# supply one.
this_dir = fileparts (mfilename ('fullpath'));
out = fullfile (this_dir, 'resources', 'zoneinfo');
else
Expand Down
Loading

0 comments on commit 464fc07

Please sign in to comment.