summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2025-06-12 05:11:58 -0700
committerFuwn <[email protected]>2025-06-12 05:11:58 -0700
commit610ade031a7a834a335e6bf0384b61be98002667 (patch)
treeb4267ed13747c5834420d9bc9e1671dbe05c9885
parentfeat: Development commit (diff)
downloadsora-testing-610ade031a7a834a335e6bf0384b61be98002667.tar.xz
sora-testing-610ade031a7a834a335e6bf0384b61be98002667.zip
feat: Development commit
-rw-r--r--Sora/Data/Booru/Tag/BooruTagXMLParser.swift54
1 files changed, 23 insertions, 31 deletions
diff --git a/Sora/Data/Booru/Tag/BooruTagXMLParser.swift b/Sora/Data/Booru/Tag/BooruTagXMLParser.swift
index 5bb005c..0a026b1 100644
--- a/Sora/Data/Booru/Tag/BooruTagXMLParser.swift
+++ b/Sora/Data/Booru/Tag/BooruTagXMLParser.swift
@@ -2,7 +2,6 @@ import Foundation
class BooruTagXMLParser: NSObject, XMLParserDelegate {
private var tags: [BooruTag] = []
- private var currentTag: BooruTag?
private var parser: XMLParser
init(data: Data) {
@@ -19,6 +18,27 @@ class BooruTagXMLParser: NSObject, XMLParserDelegate {
return tags
}
+ private func makeTag(from attributeDict: [String: String]) -> BooruTag? {
+ guard let id = attributeDict["id"],
+ let name = attributeDict["name"],
+ let countStr = attributeDict["count"],
+ let count = Int(countStr),
+ let typeStr = attributeDict["type"],
+ let type = Int(typeStr),
+ let ambiguousStr = attributeDict["ambiguous"]
+ else {
+ return nil
+ }
+
+ return BooruTag(
+ id: id,
+ name: name,
+ count: count,
+ type: type,
+ ambiguous: ambiguousStr == "true"
+ )
+ }
+
func parser(
_: XMLParser,
didStartElement elementName: String,
@@ -27,37 +47,9 @@ class BooruTagXMLParser: NSObject, XMLParserDelegate {
attributes attributeDict: [String: String] = [:]
) {
if elementName == "tag" {
- guard let id = attributeDict["id"],
- let name = attributeDict["name"],
- let countStr = attributeDict["count"],
- let count = Int(countStr),
- let typeStr = attributeDict["type"],
- let type = Int(typeStr),
- let ambiguousStr = attributeDict["ambiguous"]
- else {
- return
+ if let tag = makeTag(from: attributeDict) {
+ tags.append(tag)
}
-
- currentTag = BooruTag(
- id: id,
- name: name,
- count: count,
- type: type,
- ambiguous: ambiguousStr == "true"
- )
- }
- }
-
- func parser(
- _: XMLParser,
- didEndElement elementName: String,
- namespaceURI _: String?,
- qualifiedName _: String?
- ) {
- if elementName == "tag", let tag = currentTag {
- tags.append(tag)
-
- currentTag = nil
}
}