Skip to content

Commit

Permalink
Removed unused code and some cleanups.
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanOltmann committed Jul 6, 2023
1 parent 9d6483d commit 4fde66b
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 177 deletions.
8 changes: 4 additions & 4 deletions src/commonMain/kotlin/com/ashampoo/xmp/XMPPathFactory.kt
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ object XMPPathFactory {
@kotlin.jvm.JvmStatic
fun composeStructFieldPath(fieldNS: String, fieldName: String): String {

if (fieldNS.length == 0)
if (fieldNS.isEmpty())
throw XMPException("Empty field namespace URI", XMPError.BADSCHEMA)

if (fieldName.length == 0)
if (fieldName.isEmpty())
throw XMPException("Empty field name", XMPError.BADXPATH)

val fieldPath = XMPPathParser.expandXPath(fieldNS, fieldName)
Expand All @@ -101,10 +101,10 @@ object XMPPathFactory {
@kotlin.jvm.JvmStatic
fun composeQualifierPath(qualNS: String, qualName: String): String {

if (qualNS.length == 0)
if (qualNS.isEmpty())
throw XMPException("Empty qualifier namespace URI", XMPError.BADSCHEMA)

if (qualName.length == 0)
if (qualName.isEmpty())
throw XMPException("Empty qualifier name", XMPError.BADXPATH)

val qualPath = XMPPathParser.expandXPath(qualNS, qualName)
Expand Down
8 changes: 4 additions & 4 deletions src/commonMain/kotlin/com/ashampoo/xmp/XMPUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ object XMPUtils {
@kotlin.jvm.JvmStatic
fun convertToBoolean(value: String?): Boolean {

if (value == null || value.length == 0)
if (value.isNullOrEmpty())
throw XMPException("Empty convert-string", XMPError.BADVALUE)

val valueLowercase = value.lowercase()
Expand All @@ -54,7 +54,7 @@ object XMPUtils {
fun convertToInteger(rawValue: String?): Int {
try {

if (rawValue == null || rawValue.length == 0)
if (rawValue.isNullOrEmpty())
throw XMPException("Empty convert-string", XMPError.BADVALUE)

return if (rawValue.startsWith("0x"))
Expand All @@ -72,7 +72,7 @@ object XMPUtils {

try {

if (rawValue == null || rawValue.length == 0)
if (rawValue.isNullOrEmpty())
throw XMPException("Empty convert-string", XMPError.BADVALUE)

return if (rawValue.startsWith("0x"))
Expand All @@ -90,7 +90,7 @@ object XMPUtils {

try {

if (rawValue == null || rawValue.length == 0)
if (rawValue.isNullOrEmpty())
throw XMPException("Empty convert-string", XMPError.BADVALUE)

return rawValue.toDouble()
Expand Down
2 changes: 1 addition & 1 deletion src/commonMain/kotlin/com/ashampoo/xmp/impl/QName.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ class QName {
}

fun hasPrefix(): Boolean =
prefix != null && prefix!!.length > 0
prefix != null && prefix!!.isNotEmpty()

}
9 changes: 4 additions & 5 deletions src/commonMain/kotlin/com/ashampoo/xmp/impl/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ object Utils {
*/
fun isXMLName(name: String): Boolean {

if (name.length > 0 && !isNameStartChar(name[0]))
if (name.isNotEmpty() && !isNameStartChar(name[0]))
return false

for (i in 1 until name.length)
Expand All @@ -209,7 +209,7 @@ object Utils {
@kotlin.jvm.JvmStatic
fun isXMLNameNS(name: String): Boolean {

if (name.length > 0 && (!isNameStartChar(name[0]) || name[0] == ':'))
if (name.isNotEmpty() && (!isNameStartChar(name[0]) || name[0] == ':'))
return false

for (index in 1 until name.length)
Expand Down Expand Up @@ -257,9 +257,8 @@ object Utils {
// slow path with escaping
val buffer = StringBuilder(value.length * 4 / 3)

for (index in 0 until value.length) {

val char = value[index]
@Suppress("LoopWithTooManyJumpStatements")
for (char in value) {

if (!(escapeWhitespaces && (char == '\t' || char == '\n' || char == '\r'))) {

Expand Down
53 changes: 23 additions & 30 deletions src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPIteratorImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ class XMPIteratorImpl(
// the start node of the iteration depending on the schema and property filter
var startNode: XMPNode? = null
var initialPath: String? = null
val baseSchema = schemaNS != null && schemaNS.length > 0
val baseProperty = propPath != null && propPath.length > 0
val baseSchema = !schemaNS.isNullOrEmpty()
val baseProperty = !propPath.isNullOrEmpty()

when {

Expand Down Expand Up @@ -344,7 +344,7 @@ class XMPIteratorImpl(
segmentName = currNode.name
}

return if (parentPath == null || parentPath.length == 0) {
return if (parentPath.isNullOrEmpty()) {

segmentName

Expand Down Expand Up @@ -440,41 +440,34 @@ class XMPIteratorImpl(
*/
override fun hasNext(): Boolean {

return if (returnProperty != null) {

// hasNext has been called before
true

} else if (skipSiblings) {

false
// hasNext has been called before
if (returnProperty != null)
return true

} else if (nodeChildrenIterator.hasNext()) {
if (skipSiblings)
return false

val child = nodeChildrenIterator.next()
if (!nodeChildrenIterator.hasNext())
return false

index++
val child = nodeChildrenIterator.next()

var path: String? = null
index++

if (child.options.isSchemaNode()) {
baseNS = child.name
} else if (child.parent != null) {
// for all but the root node and schema nodes
path = accumulatePath(child, parentPath, index)
}
var path: String? = null

// report next property, skip not-leaf nodes in case options is set
if (!options.isJustLeafnodes() || !child.hasChildren()) {
returnProperty = createPropertyInfo(child, baseNS!!, path!!)
true
} else {
hasNext()
}
if (child.options.isSchemaNode())
baseNS = child.name
else if (child.parent != null)
path = accumulatePath(child, parentPath, index)

} else {
false
// report next property, skip not-leaf nodes in case options is set
if (!options.isJustLeafnodes() || !child.hasChildren()) {
returnProperty = createPropertyInfo(child, baseNS!!, path!!)
return true
}

return hasNext()
}
}

Expand Down
9 changes: 5 additions & 4 deletions src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPMetaImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -892,13 +892,14 @@ class XMPMetaImpl : XMPMeta {

} else {

if (value != null && value.toString().length > 0)
if (value != null && value.toString().isNotEmpty())
throw XMPException("Composite nodes can't have values", XMPError.BADXPATH)

// Can't change an array to a struct, or vice versa.
if (node.options.getOptions() and compositeMask != 0)
if (newOptions.getOptions() and compositeMask != node.options.getOptions() and compositeMask)
throw XMPException("Requested and existing composite form mismatch", XMPError.BADXPATH)
if (node.options.getOptions() and compositeMask != 0 &&
newOptions.getOptions() and compositeMask != node.options.getOptions() and compositeMask
)
throw XMPException("Requested and existing composite form mismatch", XMPError.BADXPATH)

node.removeChildren()
}
Expand Down
10 changes: 5 additions & 5 deletions src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPNodeUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ object XMPNodeUtils {

if (prefix == null) {

prefix = if (suggestedPrefix != null && suggestedPrefix.length != 0)
prefix = if (!suggestedPrefix.isNullOrEmpty())
schemaRegistry.registerNamespace(namespaceURI, suggestedPrefix)
else
throw XMPException("Unregistered schema namespace URI", XMPError.BADSCHEMA)
Expand Down Expand Up @@ -287,7 +287,7 @@ object XMPNodeUtils {
if (options.isArrayOrdered())
options.setArray(true)

if (options.isCompositeProperty() && itemValue != null && itemValue.toString().length > 0)
if (options.isCompositeProperty() && itemValue != null && itemValue.toString().isNotEmpty())
throw XMPException("Structs and arrays can't have values", XMPError.BADOPTIONS)

options.assertConsistency(options.getOptions())
Expand Down Expand Up @@ -417,16 +417,15 @@ object XMPNodeUtils {
* @param segment the segment containing the array index
* @param createNodes flag if new nodes are allowed to be created.
* @return Returns the index or index = -1 if not found
*
*/
private fun findIndexedItem(arrayNode: XMPNode?, segment: String?, createNodes: Boolean): Int {

var segment = segment
var index: Int

try {

segment = segment!!.substring(1, segment.length - 1)
var segment = segment!!.substring(1, segment.length - 1)

index = segment.toInt()

if (index < 1)
Expand Down Expand Up @@ -471,6 +470,7 @@ object XMPNodeUtils {
if (!currItem.options.isStruct())
throw XMPException("Field selector must be used on array of struct", XMPError.BADXPATH)

@Suppress("LoopWithTooManyJumpStatements")
for (childIndex in 1..currItem.getChildrenLength()) {

val currField = currItem.getChild(childIndex)
Expand Down
8 changes: 4 additions & 4 deletions src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPNormalizer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,14 @@ internal object XMPNormalizer {

val childValue = currChild.value

if (childValue == null || childValue.length == 0) {
if (childValue.isNullOrEmpty()) {

// Delete empty valued children that have no xml:lang.
it.remove()

} else {

// Add an xml:lang qualifier with the value "x-repair".
// Add a xml:lang qualifier with the value "x-repair".
val repairLang = XMPNode(XMPConst.XML_LANG, "x-repair")
currChild.addQualifier(repairLang)
}
Expand All @@ -220,7 +220,7 @@ internal object XMPNormalizer {
}

/**
* Visit all of the top level nodes looking for aliases. If there is
* Visit all the top level nodes looking for aliases. If there is
* no base, transplant the alias subtree. If there is a base and strict
* aliasing is on, make sure the alias and base subtrees match.
*
Expand Down Expand Up @@ -427,7 +427,7 @@ internal object XMPNormalizer {
if (!outerCall &&
(
aliasNode.name != baseNode.name ||
!aliasNode.options.equals(baseNode.options) ||
aliasNode.options != baseNode.options ||
aliasNode.getQualifierLength() != baseNode.getQualifierLength()
)
)
Expand Down
8 changes: 3 additions & 5 deletions src/commonMain/kotlin/com/ashampoo/xmp/impl/XMPRDFParser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ internal object XMPRDFParser : XMPError {
// the XMP tree name if
// it doesn't have a name yet. Make sure this name matches
// the XMP tree name.
if (xmpParent.name != null && xmpParent.name!!.length > 0) {
if (xmpParent.name != null && xmpParent.name!!.isNotEmpty()) {

if (xmpParent.name != attribute.value)
throw XMPException("Mismatched top level rdf:about values", XMPError.BADXMP)
Expand Down Expand Up @@ -1108,24 +1108,22 @@ internal object XMPRDFParser : XMPError {
*/
private fun getRDFTermKind(node: Node): Int {

val nodeName = node.nodeName

var namespace = when (node) {
is Element -> node.namespaceURI
is Attr -> node.namespaceURI
else -> throw XMPException("Unknown Node ${node.nodeType}", XMPError.BADXMP)
}

if (namespace == null &&
("about" == nodeName || "ID" == nodeName) &&
("about" == node.nodeName || "ID" == node.nodeName) &&
node is Attr && XMPConst.NS_RDF == node.ownerElement?.namespaceURI
) {
namespace = XMPConst.NS_RDF
}

if (namespace == XMPConst.NS_RDF) {

when (nodeName) {
when (node.nodeName) {

"rdf:li" ->
return RDFTERM_LI
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ object XMPPathParser {
pos.path = path

// Pull out the first component and do some special processing on it: add the schema
// namespace prefix and and see if it is an alias. The start must be a "qualName".
// namespace prefix and see if it is an alias. The start must be a "qualName".
parseRootNode(schemaNS, pos, expandedXPath)

// Now continue to process the rest of the XMPPath string.
Expand Down Expand Up @@ -166,7 +166,7 @@ object XMPPathParser {

pos.stepEnd++ // Look at the character after the leading '['.

if ('0' <= pos.path!![pos.stepEnd] && pos.path!![pos.stepEnd] <= '9') {
if (pos.path!![pos.stepEnd] in '0'..'9') {

// A numeric (decimal integer) array index.
while (
Expand Down Expand Up @@ -349,8 +349,8 @@ object XMPPathParser {
*/
private fun verifyXPathRoot(schemaNS: String?, rootProp: String): String {

// Do some basic checks on the URI and name. Try to lookup the URI. See if the name is qualified.
if (schemaNS == null || schemaNS.length == 0)
// Do some basic checks on the URI and name. Try to look up the URI. See if the name is qualified.
if (schemaNS.isNullOrEmpty())
throw XMPException("Schema namespace URI is required", XMPError.BADSCHEMA)

if (rootProp[0] == '?' || rootProp[0] == '@')
Expand Down
Loading

0 comments on commit 4fde66b

Please sign in to comment.