Skip to content

Commit 53d04f3

Browse files
Remove hasLanguage() usage
1 parent 9ee6fef commit 53d04f3

2 files changed

Lines changed: 11 additions & 16 deletions

File tree

src/literal.js

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ class Literal extends Node {
99
super()
1010
this.termType = Literal.termType
1111
this.value = value
12-
this.lang = language || ''
1312
if (language) {
13+
this.lang = language
1414
datatype = XSD.langString
1515
}
1616
// If not specified, a literal has the implied XSD.string default datatype
17-
this.datatype = NamedNode.fromValue(datatype) || XSD.string
17+
if (datatype) {
18+
this.datatype = NamedNode.fromValue(datatype)
19+
}
1820
}
1921
copy () {
2022
return new Literal(this.value, this.lang, this.datatype)
@@ -29,14 +31,6 @@ class Literal extends Node {
2931
((!this.datatype && !other.datatype) ||
3032
(this.datatype && this.datatype.equals(other.datatype)))
3133
}
32-
/**
33-
* Returns whether or not this literal has a language explicitly set.
34-
* Used by various serialization methods.
35-
* @returns {Boolean}
36-
*/
37-
hasLanguage () {
38-
return this.lang && this.lang !== ''
39-
}
4034
get language () {
4135
return this.lang
4236
}
@@ -56,11 +50,11 @@ class Literal extends Node {
5650
str = str.replace(/\n/g, '\\n')
5751
str = '"' + str + '"'
5852

59-
if (this.hasLanguage()) {
53+
if (this.language) {
6054
str += '@' + this.language
6155
} else if (!this.datatype.equals(XSD.string)) {
6256
// Only add datatype if it's not a string
63-
str += '^^' + this.datatype.toNT()
57+
str += '^^' + this.datatype.toCanonical()
6458
}
6559
return str
6660
}
@@ -147,6 +141,7 @@ class Literal extends Node {
147141
Literal.termType = 'Literal'
148142
Literal.prototype.classOrder = ClassOrder['Literal']
149143
Literal.prototype.datatype = XSD.string
144+
Literal.prototype.lang = ''
150145
Literal.prototype.isVar = 0
151146

152147
module.exports = Literal

src/serializer.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -499,8 +499,8 @@ __Serializer.prototype.atomicTermToN3 = function atomicTermToN3(expr, stats) {
499499
}
500500
}
501501
var str = this.stringToN3(expr.value);
502-
if (expr.hasLanguage()){
503-
str+= '@' + expr.lang;
502+
if (expr.language){
503+
str+= '@' + expr.language;
504504
} else if (!expr.datatype.equals(XSD.string)) {
505505
str+= '^^' + this.termToN3(expr.datatype, stats);
506506
}
@@ -866,7 +866,7 @@ __Serializer.prototype.statementsToXML = function(sts) {
866866
(st.object.datatype.equals(XSD.string)
867867
? ''
868868
: ' rdf:datatype="'+escapeForXML(st.object.datatype.uri)+'"') +
869-
(st.object.hasLanguage() ? ' xml:lang="'+st.object.lang+'"' : '') +
869+
(st.object.language ? ' xml:lang="'+st.object.language+'"' : '') +
870870
'>' + escapeForXML(st.object.value) +
871871
'</'+ t +'>']);
872872
break;
@@ -930,7 +930,7 @@ __Serializer.prototype.statementsToXML = function(sts) {
930930
case 'Literal':
931931
results = results.concat(['<'+qname(st.predicate)
932932
+ (st.object.datatype.equals(XSD.string) ? '' : ' rdf:datatype="'+escapeForXML(st.object.datatype.value)+'"')
933-
+ (st.object.hasLanguage() ? ' xml:lang="'+st.object.lang+'"' : '')
933+
+ (st.object.language ? ' xml:lang="'+st.object.language+'"' : '')
934934
+ '>' + escapeForXML(st.object.value)
935935
+ '</'+qname(st.predicate)+'>']);
936936
break;

0 commit comments

Comments
 (0)