func parse()

in Cyborg/VectorDrawableParser.swift [747:801]


    func parse(element: String, attributes: [(XMLString, XMLString)]) -> ParseError? {
        if element == androidResourceAttribute {
            for (key, value) in attributes {
                if String(withoutCopying: key) != "name" || String(withoutCopying: value) != PathProperty.fillColor.rawValue {
                    return "Only \(PathProperty.fillColor.rawValue) is supported in \(androidResourceAttribute) elements."
                } else {
                    return nil
                }
            }
            return nil
        } else if element == "gradient" {
            return parseAttributes(attributes) { (property: GradientProperty, value) -> (ParseError?) in
                switch property {
                case .centerColor: return assign(value, to: &centerColor, creatingWith: Color.init)
                case .startY: return assignFloat(value, to: &startY)
                case .startX: return assignFloat(value, to: &startX)
                case .endY: return assignFloat(value, to: &endY)
                case .endX: return assignFloat(value, to: &endX)
                case .type: return assign(value, to: &type)
                case .startcolor: return assign(value, to: &startColor, creatingWith: Color.init)
                case .endColor: return assign(value, to: &endColor, creatingWith: Color.init)
                case .tileMode: return assign(value, to: &tileMode)
                case .centerX: return assignFloat(value, to: &centerX)
                case .centerY: return assignFloat(value, to: &centerY)
                case .gradientRadius: return assignFloat(value, to: &radius)
                }
            }
        } else if element == "item" {
            var offset: CGFloat?
            var color: Color?
            let error = parseAttributes(attributes) { (property: ItemProperty, value) -> (ParseError?) in
                switch property {
                case .offset: return assignFloat(value, to: &offset)
                case .color: return assign(value, to: &color, creatingWith: Color.init)
                }
            }
            if let error = error {
                return error
            } else {
                switch (color, offset) {
                case (.some(let color), .some(let offset)):
                    offsets.append(VectorDrawable.Gradient.Offset(amount: offset, color: color))
                    return nil
                case (.none, .some):
                    return "Missing color"
                case (.some, .none):
                    return "Missing offset"
                case (.none, .none):
                    return "Missing color and offset"
                }
            }
        } else {
            return "Invalid element \"\(element)\""
        }
    }