Skip to content

Commit

Permalink
Keep original field name
Browse files Browse the repository at this point in the history
  • Loading branch information
FObermaier committed Sep 17, 2024
1 parent 64278c9 commit e777ba5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ public static Encoding ReadDbfEncoding(this Stream stream)
public static void WriteDbaseFieldDescriptor(this Stream stream, DbfField field, Encoding encoding)
{
encoding = encoding ?? Dbf.DefaultEncoding;
var name = field.Name.PadRight(Dbf.MaxFieldNameLength, char.MinValue); // Field name must have empty space zero-filled

var name = field.OriginalName.PadRight(Dbf.MaxFieldNameLength, char.MinValue); // Field name must have empty space zero-filled

stream.WriteString(name, Dbf.MaxFieldNameLength, encoding);
stream.WriteNullBytes(1);
Expand Down
16 changes: 8 additions & 8 deletions src/NetTopologySuite.IO.Esri.Shapefile/Dbf/Fields/DbfField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ namespace NetTopologySuite.IO.Esri.Dbf.Fields
public abstract class DbfField
{
// TODO: Spit DbfField into DbfFieldDefinition (Without Value property) and DbfFieldValue
private readonly string _name;

/// <summary>
/// Original field name
/// </summary>
internal string OriginalName { get; }

/// <summary>
/// Field Name.
/// </summary>
Expand All @@ -23,7 +28,7 @@ public string Name
get
{
string suffix = DuplicateCount > 0 ? $"_{DuplicateCount}" : string.Empty;
return $"{_name}{suffix}";
return $"{OriginalName}{suffix}";
}
}

Expand Down Expand Up @@ -82,17 +87,12 @@ internal DbfField(string name, DbfType type, int length, int precision)
throw new ArgumentException($"Ivalid dBASE field precision: {precision}.", nameof(precision));
}

_name = name;
OriginalName = name;
FieldType = type;
Length = length;
NumericScale = precision;
}

private bool IsValidFieldNameChar(char c)
{
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_' || (c >= '0' && c <= '9');
}

/// <inheritdoc/>
public override string ToString()
{
Expand Down

0 comments on commit e777ba5

Please sign in to comment.