Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
openstructure
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
schwede
openstructure
Commits
4190561f
Commit
4190561f
authored
3 months ago
by
Studer Gabriel
Browse files
Options
Downloads
Patches
Plain Diff
mmcif writer bugfix
Multiline strings that are treated with semi-colons don't need quotes
parent
d8999feb
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
modules/io/src/mol/star_writer.hh
+115
-122
115 additions, 122 deletions
modules/io/src/mol/star_writer.hh
with
115 additions
and
122 deletions
modules/io/src/mol/star_writer.hh
+
115
−
122
View file @
4190561f
...
@@ -107,144 +107,137 @@ public:
...
@@ -107,144 +107,137 @@ public:
if
(
string_value
==
""
)
{
if
(
string_value
==
""
)
{
value
.
value_
=
"?"
;
value
.
value_
=
"?"
;
}
else
{
}
else
{
// string requires quotes if any of the following is True
if
(
StarWriterValue
::
HasNewline
(
string_value
))
{
// information from https://www.iucr.org/resources/cif/spec/version1.1/cifsyntax
value
.
value_
=
"
\n
;"
+
string_value
+
"
\n
;
\n
"
;
// * space in string
// * any string that starts with any of the following strings
// * _
// * #
// * $
// * '
// * "
// * [
// * ]
// * ;
// * data_ (case insensitive)
// * save_ (case insensitive)
// * any string that is equal to any of the following reserved words
// * loop_ (case insensitive)
// * stop_ (case insensitive)
// * global_ (case insensitive)
bool
is_multiline
=
false
;
bool
needs_quotes
=
false
;
// newline in string
for
(
char
c
:
string_value
)
{
if
(
c
==
'\n'
)
{
is_multiline
=
true
;
break
;
}
}
}
else
if
(
StarWriterValue
::
NeedsQuotes
(
string_value
))
{
// space in string
value
.
value_
=
"
\"
"
+
string_value
+
"
\"
"
;
for
(
char
c
:
string_value
)
{
if
(
isspace
(
c
)
&&
c
!=
'\n'
)
{
// linebreaks evaluate to true in isspace but do not require quotes
needs_quotes
=
true
;
break
;
}
}
}
else
{
// any string that starts with any of the special single characters
value
.
value_
=
string_value
;
if
(
!
needs_quotes
)
{
switch
(
string_value
[
0
])
{
case
'_'
:
{
needs_quotes
=
true
;
break
;
}
case
'#'
:
{
needs_quotes
=
true
;
break
;
}
case
'$'
:
{
needs_quotes
=
true
;
break
;
}
case
'\''
:
{
needs_quotes
=
true
;
break
;
}
case
'\"'
:
{
needs_quotes
=
true
;
break
;
}
case
'['
:
{
needs_quotes
=
true
;
break
;
}
case
']'
:
{
needs_quotes
=
true
;
break
;
}
case
';'
:
{
needs_quotes
=
true
;
break
;
}
}
}
}
}
return
value
;
}
// any string that starts with any of the special multi character thingies
static
bool
NeedsQuotes
(
const
String
&
v
)
{
if
(
!
needs_quotes
&&
string_value
.
size
()
>=
5
&&
string_value
[
4
]
==
'_'
)
{
// need to do case insensitive checking
// string requires quotes if any of the following is True
if
((
string_value
[
0
]
==
'd'
||
string_value
[
0
]
==
'D'
)
&&
// information from https://www.iucr.org/resources/cif/spec/version1.1/cifsyntax
(
string_value
[
1
]
==
'a'
||
string_value
[
1
]
==
'A'
)
&&
// * space in string
(
string_value
[
2
]
==
't'
||
string_value
[
2
]
==
'T'
)
&&
// * any string that starts with any of the following strings
(
string_value
[
3
]
==
'a'
||
string_value
[
3
]
==
'A'
))
{
// * _
needs_quotes
=
true
;
// * #
}
// * $
if
((
string_value
[
0
]
==
's'
||
string_value
[
0
]
==
'S'
)
&&
// * '
(
string_value
[
1
]
==
'a'
||
string_value
[
1
]
==
'A'
)
&&
// * "
(
string_value
[
2
]
==
'v'
||
string_value
[
2
]
==
'V'
)
&&
// * [
(
string_value
[
3
]
==
'e'
||
string_value
[
3
]
==
'E'
))
{
// * ]
needs_quotes
=
true
;
// * ;
}
// * data_ (case insensitive)
// * save_ (case insensitive)
// * any string that is equal to any of the following reserved words
// * loop_ (case insensitive)
// * stop_ (case insensitive)
// * global_ (case insensitive)
// space in string
for
(
char
c
:
v
)
{
if
(
isspace
(
c
)
&&
c
!=
'\n'
)
{
// linebreaks evaluate to true in isspace but do not need quotes
// they are handled with semi-colons
return
true
;
}
}
}
// any string that is exactly one of the reserved words
// any string that starts with any of the special single characters
if
(
!
needs_quotes
&&
string_value
.
size
()
==
5
&&
string_value
[
4
]
==
'_'
)
{
switch
(
v
[
0
])
{
// need to do case insensitive checking
case
'_'
:
{
if
((
string_value
[
0
]
==
'l'
||
string_value
[
0
]
==
'L'
)
&&
return
true
;
(
string_value
[
1
]
==
'o'
||
string_value
[
1
]
==
'O'
)
&&
}
(
string_value
[
2
]
==
'o'
||
string_value
[
2
]
==
'O'
)
&&
case
'#'
:
{
(
string_value
[
3
]
==
'p'
||
string_value
[
3
]
==
'P'
))
{
return
true
;
needs_quotes
=
true
;
}
}
case
'$'
:
{
if
((
string_value
[
0
]
==
's'
||
string_value
[
0
]
==
'S'
)
&&
return
true
;
(
string_value
[
1
]
==
't'
||
string_value
[
1
]
==
'T'
)
&&
}
(
string_value
[
2
]
==
'o'
||
string_value
[
2
]
==
'O'
)
&&
case
'\''
:
{
(
string_value
[
3
]
==
'p'
||
string_value
[
3
]
==
'P'
))
{
return
true
;
needs_quotes
=
true
;
}
}
case
'\"'
:
{
return
true
;
}
}
case
'['
:
{
return
true
;
}
case
']'
:
{
return
true
;
}
case
';'
:
{
return
true
;
}
default
:
{
break
;
}
}
if
(
!
needs_quotes
&&
string_value
.
size
()
==
7
&&
string_value
[
6
]
==
'_'
)
{
// any string that starts with any of the special multi character thingies
// need to do case insensitive checking
if
(
v
.
size
()
>=
5
&&
v
[
4
]
==
'_'
)
{
if
((
string_value
[
0
]
==
'g'
||
string_value
[
0
]
==
'G'
)
&&
// need to do case insensitive checking
(
string_value
[
1
]
==
'l'
||
string_value
[
1
]
==
'L'
)
&&
if
((
v
[
0
]
==
'd'
||
v
[
0
]
==
'D'
)
&&
(
string_value
[
2
]
==
'o'
||
string_value
[
2
]
==
'O'
)
&&
(
v
[
1
]
==
'a'
||
v
[
1
]
==
'A'
)
&&
(
string_value
[
3
]
==
'b'
||
string_value
[
3
]
==
'B'
)
&&
(
v
[
2
]
==
't'
||
v
[
2
]
==
'T'
)
&&
(
string_value
[
4
]
==
'a'
||
string_value
[
4
]
==
'A'
)
&&
(
v
[
3
]
==
'a'
||
v
[
3
]
==
'A'
))
{
(
string_value
[
5
]
==
'l'
||
string_value
[
5
]
==
'L'
))
{
return
true
;
needs_quotes
=
true
;
}
}
if
((
v
[
0
]
==
's'
||
v
[
0
]
==
'S'
)
&&
(
v
[
1
]
==
'a'
||
v
[
1
]
==
'A'
)
&&
(
v
[
2
]
==
'v'
||
v
[
2
]
==
'V'
)
&&
(
v
[
3
]
==
'e'
||
v
[
3
]
==
'E'
))
{
return
true
;
}
}
}
if
(
is_multiline
&&
needs_quotes
)
{
// any string that is exactly one of the reserved words
value
.
value_
=
"
\n
;
\"
"
+
string_value
+
"
\"\n
;
\n
"
;
if
(
v
.
size
()
==
5
&&
v
[
4
]
==
'_'
)
{
// need to do case insensitive checking
if
((
v
[
0
]
==
'l'
||
v
[
0
]
==
'L'
)
&&
(
v
[
1
]
==
'o'
||
v
[
1
]
==
'O'
)
&&
(
v
[
2
]
==
'o'
||
v
[
2
]
==
'O'
)
&&
(
v
[
3
]
==
'p'
||
v
[
3
]
==
'P'
))
{
return
true
;
}
}
else
if
(
needs_quotes
)
{
if
((
v
[
0
]
==
's'
||
v
[
0
]
==
'S'
)
&&
value
.
value_
=
"
\"
"
+
string_value
+
"
\"
"
;
(
v
[
1
]
==
't'
||
v
[
1
]
==
'T'
)
&&
(
v
[
2
]
==
'o'
||
v
[
2
]
==
'O'
)
&&
(
v
[
3
]
==
'p'
||
v
[
3
]
==
'P'
))
{
return
true
;
}
}
else
if
(
is_multiline
)
{
}
value
.
value_
=
"
\n
;"
+
string_value
+
"
\n
;
\n
"
;
if
(
v
.
size
()
==
7
&&
v
[
6
]
==
'_'
)
{
// need to do case insensitive checking
if
((
v
[
0
]
==
'g'
||
v
[
0
]
==
'G'
)
&&
(
v
[
1
]
==
'l'
||
v
[
1
]
==
'L'
)
&&
(
v
[
2
]
==
'o'
||
v
[
2
]
==
'O'
)
&&
(
v
[
3
]
==
'b'
||
v
[
3
]
==
'B'
)
&&
(
v
[
4
]
==
'a'
||
v
[
4
]
==
'A'
)
&&
(
v
[
5
]
==
'l'
||
v
[
5
]
==
'L'
))
{
return
true
;
}
}
else
{
}
value
.
value_
=
string_value
;
return
false
;
}
static
bool
HasNewline
(
const
String
&
v
)
{
for
(
char
c
:
v
)
{
if
(
c
==
'\n'
)
{
return
true
;
}
}
}
}
return
v
al
u
e
;
return
f
al
s
e
;
}
}
const
String
&
GetValue
()
const
{
return
value_
;
}
const
String
&
GetValue
()
const
{
return
value_
;
}
private
:
private
:
String
value_
;
String
value_
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment