Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/c_geometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,19 @@
#include <cctype>
#include <stdint.h>

c_geometry::c_geometry()
/**
* geometry_field_separator - Determine whether a character separates fields
* @character: Character read from a geometry card
*
* Return: true for NEC commas, whitespace, and the line terminator.
*/
static bool geometry_field_separator(char character)
{
return (std::isspace(static_cast<unsigned char>(character)) != 0) ||
(character == ',') || (character == '\0');
}

c_geometry::c_geometry()
: patch_x1(0,0,0), patch_x2(0,0,0), patch_x3(0,0,0), patch_x4(0,0,0) {
n_segments = 0;
np = 0; // n_segments is the number of segments
Expand Down Expand Up @@ -2383,7 +2395,7 @@ void c_geometry::parse_geometry_card_line(const char* line_buf, char *gm,
integer_params[i] = atoi( &line_buf[line_idx] );

line_idx--;
while( (line_buf[++line_idx] != ' ') && (line_buf[line_idx] != ',') && (line_buf[line_idx] != '\0') )
while( !geometry_field_separator(line_buf[++line_idx]) )
{
if ( ((line_buf[line_idx] < '0') || (line_buf[line_idx] > '9')) &&
(line_buf[line_idx] != '+') && (line_buf[line_idx] != '-') )
Expand Down Expand Up @@ -2419,7 +2431,7 @@ void c_geometry::parse_geometry_card_line(const char* line_buf, char *gm,
real_params[i] = atof( &line_buf[line_idx] );

line_idx--;
while( (line_buf[++line_idx] != ' ') && (line_buf[line_idx] != ',') && (line_buf[line_idx] != '\0') )
while( !geometry_field_separator(line_buf[++line_idx]) )
{
if ( ((line_buf[line_idx] < '0') || (line_buf[line_idx] > '9')) &&
(line_buf[line_idx] != '.') && (line_buf[line_idx] != '+') &&
Expand Down
21 changes: 21 additions & 0 deletions src/nec2cpp_tb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <cstdio>
#include <cstring>
#include <memory>
#include <string>
#include <sstream>

Expand Down Expand Up @@ -336,6 +337,26 @@ TEST_CASE("load_line(istream) drains over-length CM, next line parses as CE",
REQUIRE(buf[1] == 'E');
}

TEST_CASE("geometry parser accepts tab-separated fields", "[geometry][parser]") {
// Build one valid wire deck with tabs delimiting every geometry field.
const char deck[] =
"GW\t1\t3\t0\t0\t0\t0\t0\t1\t0.001\n"
"GE\t0\n";
std::unique_ptr<FILE, decltype(&std::fclose)> input(
std::tmpfile(), &std::fclose);
REQUIRE(input != nullptr);
REQUIRE(std::fwrite(deck, 1, sizeof(deck) - 1, input.get()) ==
sizeof(deck) - 1);
std::rewind(input.get());

// Parse through the public file interface and retain the generated segments.
nec_context nec;
nec.initialize();
c_geometry* geometry = nec.get_geometry();
REQUIRE_NOTHROW(geometry->parse_geometry(&nec, input.get()));
REQUIRE(geometry->n_segments == 3);
}

TEST_CASE("load_line returns EOF when an over-length line is the last line",
"[load_line]") {
/* No trailing newline: the drain hits EOF mid-tail. The fill loop's
Expand Down
Loading