Strip spaces from responses, unless caller wants them
This commit is contained in:
1 parent
cb57796dfc
commit
c72f89f1d7
1 file changed
+24
-1
@@ -7,6 +7,7 @@ package go3270
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"net"
|
"net"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Field is a field on the 3270 screen.
|
// Field is a field on the 3270 screen.
|
||||||
@@ -44,6 +45,13 @@ type Field struct {
|
|||||||
// Name is the name of this field, which is used to get the user-entered
|
// Name is the name of this field, which is used to get the user-entered
|
||||||
// data. All writeable fields on a screen must have a unique name.
|
// data. All writeable fields on a screen must have a unique name.
|
||||||
Name string
|
Name string
|
||||||
|
|
||||||
|
// KeepSpaces will prevent the strings.TrimSpace() function from being
|
||||||
|
// called on the field value. Generally you want leading and trailing
|
||||||
|
// spaces trimmed from fields in 3270 before processing, but if you are
|
||||||
|
// building a whitespace-sensitive application, you can ask for the
|
||||||
|
// original, un-trimmed value for a field by setting this to true.
|
||||||
|
KeepSpaces bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Color is a 3270 extended field attribute color value
|
// Color is a 3270 extended field attribute color value
|
||||||
@@ -147,7 +155,22 @@ func ShowScreen(screen Screen, values map[string]string, crow, ccol int,
|
|||||||
return Response{}, err
|
return Response{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return readResponse(conn, fm)
|
response, err := readResponse(conn, fm)
|
||||||
|
if err != nil {
|
||||||
|
return response, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Strip leading+trailing spaces from field values
|
||||||
|
for _, fld := range screen {
|
||||||
|
if !fld.KeepSpaces {
|
||||||
|
if _, ok := response.Values[fld.Name]; ok {
|
||||||
|
response.Values[fld.Name] =
|
||||||
|
strings.TrimSpace(response.Values[fld.Name])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return response, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// sba is the "set buffer address" 3270 command.
|
// sba is the "set buffer address" 3270 command.
|
||||||
|
|||||||
Reference in new issue
Block a user