Skip to content

Commit

Permalink
Rename position -> pos.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexhsamuel committed Jun 26, 2017
1 parent dee9e8c commit 932fe9a
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 80 deletions.
6 changes: 3 additions & 3 deletions cxx/fixfmt/bool.hh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public:
int size = 5;
string true_str = "True";
string false_str = "False";
float position = PAD_POSITION_LEFT_JUSTIFY;
float pos = PAD_POS_LEFT_JUSTIFY;
};

Bool() = default;
Expand Down Expand Up @@ -78,8 +78,8 @@ private:
inline void
Bool::set_up()
{
true_ = palide(args_.true_str, args_.size, "", " ", 1, args_.position);
false_ = palide(args_.false_str, args_.size, "", " ", 1, args_.position);
true_ = palide(args_.true_str, args_.size, "", " ", 1, args_.pos);
false_ = palide(args_.false_str, args_.size, "", " ", 1, args_.pos);
}


Expand Down
4 changes: 2 additions & 2 deletions cxx/fixfmt/number.hh
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ Number::format_inf_nan(
// Try to put it in the integer part.
if (len <= (int) width_)
result = pad(
pad(result, size, " ", PAD_POSITION_RIGHT_JUSTIFY),
width_, " ", PAD_POSITION_LEFT_JUSTIFY);
pad(result, size, " ", PAD_POS_RIGHT_JUSTIFY),
width_, " ", PAD_POS_LEFT_JUSTIFY);
else
// Doesn't fit at all.
string_truncate(result, width_);
Expand Down
11 changes: 5 additions & 6 deletions cxx/fixfmt/string.hh
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public:
int size = 8;
string ellipsis = ELLIPSIS;
string pad = " ";
float elide_position = 1;
float pad_position = 1;
float elide_pos = 1;
float pad_pos = 1;
};

String() = default;
Expand Down Expand Up @@ -62,8 +62,8 @@ String::check(
Args const& args)
{
assert(args.ellipsis.length() <= (size_t) args.size);
assert(0 <= args.elide_position && args.elide_position <= 1);
assert(0 <= args.pad_position && args.pad_position <= 1);
assert(0 <= args.elide_pos && args.elide_pos <= 1);
assert(0 <= args.pad_pos && args.pad_pos <= 1);
}


Expand All @@ -73,8 +73,7 @@ String::operator()(
const
{
return palide(
str, args_.size, args_.ellipsis, args_.pad, args_.elide_position,
args_.pad_position);
str, args_.size, args_.ellipsis, args_.pad, args_.elide_pos, args_.pad_pos);
}


Expand Down
32 changes: 16 additions & 16 deletions cxx/fixfmt/text.hh
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,9 @@ fill(
}


float constexpr PAD_POSITION_LEFT_JUSTIFY = 1;
float constexpr PAD_POSITION_RIGHT_JUSTIFY = 0;
float constexpr PAD_POSITION_CENTER = 0.5;
float constexpr PAD_POS_LEFT_JUSTIFY = 1.0;
float constexpr PAD_POS_CENTER = 0.5;
float constexpr PAD_POS_RIGHT_JUSTIFY = 0.0;


/**
Expand All @@ -200,15 +200,15 @@ pad(
string const& str,
size_t const length,
string const& pad=" ",
float position=PAD_POSITION_LEFT_JUSTIFY)
float const pos=PAD_POS_LEFT_JUSTIFY)
{
assert(string_length(pad) > 0);
assert(0 <= position);
assert(position <= 1);
assert(0 <= pos);
assert(pos <= 1);
size_t const str_len = string_length(str);
if (str_len < length) {
size_t const pad_len = length - str_len;
size_t const left_len = (size_t) round((1 - position) * pad_len);
size_t const left_len = (size_t) round((1 - pos) * pad_len);
string const result =
fill(pad, left_len) + str + fill(pad, pad_len - left_len);
assert(string_length(result) == length);
Expand All @@ -220,15 +220,15 @@ pad(


/*
* Deprecated. Use `pad(str, len, pad, PAD_POSITION_CENTER)` instead.
* Deprecated. Use `pad(str, len, pad, PAD_POS_CENTER)` instead.
*/
inline string
center(
string const& str,
size_t const length,
string const& pad=" ")
{
return fixfmt::pad(str, length, pad, PAD_POSITION_CENTER);
return fixfmt::pad(str, length, pad, PAD_POS_CENTER);
}


Expand All @@ -241,19 +241,19 @@ elide(
string const& str,
size_t const max_length,
string const& ellipsis=ELLIPSIS,
float const position=1)
float const pos=1)
{
size_t const ellipsis_len = string_length(ellipsis);
assert(max_length >= ellipsis_len);
assert(0 <= position);
assert(position <= 1);
assert(0 <= pos);
assert(pos <= 1);

size_t const length = string_length(str);
if (length <= max_length)
return str;
else {
size_t const keep = max_length - ellipsis_len;
size_t const nleft = (size_t) round(position * keep);
size_t const nleft = (size_t) round(pos * keep);
size_t const nright = keep - nleft;
string elided;
if (nleft > 0)
Expand All @@ -276,11 +276,11 @@ palide(
size_t const length,
string const& ellipsis=ELLIPSIS,
string const& pad=" ",
float const elide_position=1,
float pad_position=1)
float const elide_pos=1,
float pad_pos=1)
{
return fixfmt::pad(
elide(str, length, ellipsis, elide_position), length, pad, pad_position);
elide(str, length, ellipsis, elide_pos), length, pad, pad_pos);
}


Expand Down
14 changes: 7 additions & 7 deletions python/fixfmt/PyBool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ namespace {
int tp_init(PyBool* self, PyObject* args, PyObject* kw_args)
{
static char const* arg_names[] = {
"true", "false", "size", "position", nullptr };
"true", "false", "size", "pos", nullptr };
char const* true_str = "true";
char const* false_str = "false";
int size = -1;
float position= fixfmt::PAD_POSITION_LEFT_JUSTIFY;
float pos = fixfmt::PAD_POS_LEFT_JUSTIFY;
if (!PyArg_ParseTupleAndKeywords(
args, kw_args, "|ssif", (char**) arg_names,
&true_str, &false_str, &size, &position))
&true_str, &false_str, &size, &pos))
return -1;

if (size < 0)
Expand All @@ -37,7 +37,7 @@ int tp_init(PyBool* self, PyObject* args, PyObject* kw_args)

new(self) PyBool;
self->fmt_ = std::make_unique<fixfmt::Bool>(
fixfmt::Bool::Args{size, string(true_str), string(false_str), position});
fixfmt::Bool::Args{size, string(true_str), string(false_str), pos});
return 0;
}

Expand Down Expand Up @@ -67,9 +67,9 @@ ref<Object> get_false(PyBool* const self, void* /* closure */)
}


ref<Object> get_position(PyBool* const self, void* /* closure */)
ref<Object> get_pos(PyBool* const self, void* /* closure */)
{
return Float::FromDouble(self->fmt_->get_args().position);
return Float::FromDouble(self->fmt_->get_args().pos);
}


Expand All @@ -93,7 +93,7 @@ ref<Object> get_width(PyBool* const self, void* /* closure */)

auto getsets = GetSets<PyBool>()
.add_get<get_false> ("false")
.add_get<get_position> ("position")
.add_get<get_pos> ("pos")
.add_get<get_size> ("size")
.add_get<get_true> ("true")
.add_get<get_width> ("width")
Expand Down
24 changes: 12 additions & 12 deletions python/fixfmt/PyString.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@ namespace {
int tp_init(PyString* self, PyObject* args, PyObject* kw_args)
{
static char const* arg_names[]
= {"size", "ellipsis", "pad", "elide_position", "pad_position", nullptr};
= {"size", "ellipsis", "pad", "elide_pos", "pad_pos", nullptr};

int size;
char* ellipsis = nullptr;
char* pad = nullptr;
float elide_position = 1;
float pad_position = fixfmt::PAD_POSITION_LEFT_JUSTIFY;
float elide_pos = 1;
float pad_pos = fixfmt::PAD_POS_LEFT_JUSTIFY;
#if PY3K
if (!PyArg_ParseTupleAndKeywords(
args, kw_args, "i|ssff", (char**) arg_names,
&size, &ellipsis, &pad, &elide_position, &pad_position))
&size, &ellipsis, &pad, &elide_pos, &pad_pos))
return -1;
#else
if (!PyArg_ParseTupleAndKeywords(
args, kw_args, "i|etetff", (char**) arg_names,
&size, "utf-8", &ellipsis, "utf-8", &pad, &elide_position, &pad_position))
&size, "utf-8", &ellipsis, "utf-8", &pad, &elide_pos, &pad_pos))
return -1;
PyMemGuard ellipsis_guard(ellipsis);
PyMemGuard pad_guard(pad);
Expand All @@ -48,7 +48,7 @@ int tp_init(PyString* self, PyObject* args, PyObject* kw_args)
new(self) PyString;
self->fmt_ = std::make_unique<fixfmt::String>(
fixfmt::String::Args{
size, ellipsis, pad, (float) elide_position, (float) pad_position});
size, ellipsis, pad, (float) elide_pos, (float) pad_pos});
return 0;
}

Expand Down Expand Up @@ -88,15 +88,15 @@ ref<Object> get_pad(PyString* const self, void* /* closure */)
}


ref<Object> get_pad_position(PyString* const self, void* /* closure */)
ref<Object> get_pad_pos(PyString* const self, void* /* closure */)
{
return Float::FromDouble(self->fmt_->get_args().pad_position);
return Float::FromDouble(self->fmt_->get_args().pad_pos);
}


ref<Object> get_elide_position(PyString* const self, void* /* closure */)
ref<Object> get_elide_pos(PyString* const self, void* /* closure */)
{
return Float::FromDouble(self->fmt_->get_args().elide_position);
return Float::FromDouble(self->fmt_->get_args().elide_pos);
}


Expand All @@ -115,8 +115,8 @@ ref<Object> get_width(PyString* const self, void* /* closure */)
auto getsets = GetSets<PyString>()
.add_get<get_ellipsis> ("ellipsis")
.add_get<get_pad> ("pad")
.add_get<get_pad_position> ("pad_position")
.add_get<get_elide_position> ("elide_position")
.add_get<get_pad_pos> ("pad_pos")
.add_get<get_elide_pos> ("elide_pos")
.add_get<get_size> ("size")
.add_get<get_width> ("width")
;
Expand Down
39 changes: 19 additions & 20 deletions python/fixfmt/functions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -128,22 +128,21 @@ ref<Object> center(Module* module, Tuple* args, Dict* kw_args)

ref<Object> pad(Module* module, Tuple* args, Dict* kw_args)
{
static char const* arg_names[] = {
"string", "length", "pad", "position", nullptr};
static char const* arg_names[] = {"string", "length", "pad", "pos", nullptr};
char* str;
int length;
char* pad = nullptr;
float position = fixfmt::PAD_POSITION_LEFT_JUSTIFY;
float pos = fixfmt::PAD_POS_LEFT_JUSTIFY;
#if PY3
Arg::ParseTupleAndKeywords(
args, kw_args,
"sI|sf", arg_names, &str, &length, &pad,
&position, nullptr);
&pos, nullptr);
#else
Arg::ParseTupleAndKeywords(
args, kw_args,
"etI|etf", arg_names, "utf-8", &str, &length, "utf-8", &pad,
&position, nullptr);
&pos, nullptr);
PyMemGuard str_guard(str);
PyMemGuard pad_guard(pad);
#endif
Expand All @@ -152,61 +151,61 @@ ref<Object> pad(Module* module, Tuple* args, Dict* kw_args)
pad = (char*) " ";
if (strlen(pad) == 0)
throw ValueError("empty pad");
if (position < 0 or position > 1)
throw ValueError("position out of range");
if (pos < 0 or pos > 1)
throw ValueError("pos out of range");

return Unicode::from(fixfmt::pad(string(str), length, pad, (float) position));
return Unicode::from(fixfmt::pad(string(str), length, pad, (float) pos));
}


ref<Object> elide(Module* module, Tuple* args, Dict* kw_args)
{
static char const* arg_names[] = {
"string", "length", "ellipsis", "position", nullptr};
"string", "length", "ellipsis", "pos", nullptr};
char* str;
int length;
char* ellipsis = nullptr;
float position = 1;
float pos = 1;
#if PY3
Arg::ParseTupleAndKeywords(
args, kw_args,
"sI|sf", arg_names, &str, &length, &ellipsis, &position);
"sI|sf", arg_names, &str, &length, &ellipsis, &pos);
#else
Arg::ParseTupleAndKeywords(
args, kw_args,
"etI|etf", arg_names, "utf-8", &str, &length, "utf-8", &ellipsis, &position);
"etI|etf", arg_names, "utf-8", &str, &length, "utf-8", &ellipsis, &pos);
PyMemGuard str_guard(str);
PyMemGuard ellipsis_guard(ellipsis);
#endif

if (ellipsis == nullptr)
ellipsis = (char*) fixfmt::ELLIPSIS;

string r = fixfmt::elide(string(str), length, string(ellipsis), position);
string r = fixfmt::elide(string(str), length, string(ellipsis), pos);
return Unicode::from(r);
}


ref<Object> palide(Module* module, Tuple* args, Dict* kw_args)
{
static char const* arg_names[] = {
"string", "length", "ellipsis", "pad", "elide_position",
"pad_position", nullptr };
"string", "length", "ellipsis", "pad", "elide_pos",
"pad_pos", nullptr };
char* str;
int length;
char* ellipsis = nullptr;
char* pad = nullptr;
float elide_position = 1;
float pad_position = fixfmt::PAD_POSITION_LEFT_JUSTIFY;
float elide_pos = 1;
float pad_pos = fixfmt::PAD_POS_LEFT_JUSTIFY;
#if PY3K
Arg::ParseTupleAndKeywords(
args, kw_args, "sI|ssff", arg_names,
&str, &length, &ellipsis, &pad, &elide_position, &pad_position);
&str, &length, &ellipsis, &pad, &elide_pos, &pad_pos);
#else
Arg::ParseTupleAndKeywords(
args, kw_args, "etI|etetff", arg_names,
"utf-8", &str, &length, "utf-8", &ellipsis, "utf-8", &pad,
&elide_position, &pad_position);
&elide_pos, &pad_pos);
PyMemGuard str_guard(str);
PyMemGuard ellipsis_guard(ellipsis);
PyMemGuard pad_guard(pad);
Expand All @@ -220,7 +219,7 @@ ref<Object> palide(Module* module, Tuple* args, Dict* kw_args)
throw ValueError("empty pad");

return Unicode::from(fixfmt::palide(
string(str), length, string(ellipsis), pad, elide_position, pad_position));
string(str), length, string(ellipsis), pad, elide_pos, pad_pos));
}


Expand Down
Loading

0 comments on commit 932fe9a

Please sign in to comment.