-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #428 from lynchsft/anchor_tag_and_autoaliasing
Implement Anchor coding, Tag coding and redundancy auto-aliasing
- Loading branch information
Showing
26 changed files
with
1,687 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// | ||
// Anchor.swift | ||
// Yams | ||
// | ||
// Created by Adora Lynch on 8/9/24. | ||
// Copyright (c) 2024 Yams. All rights reserved. | ||
|
||
import Foundation | ||
|
||
/// A representation of a YAML tag see: https://yaml.org/spec/1.2.2/ | ||
/// Types interested in Encoding and Decoding Anchors should | ||
/// conform to YamlAnchorProviding and YamlAnchorCoding respectively. | ||
public final class Anchor: RawRepresentable, ExpressibleByStringLiteral, Codable, Hashable { | ||
|
||
/// A CharacterSet containing only characters which are permitted by the underlying cyaml implementation | ||
public static let permittedCharacters = CharacterSet.lowercaseLetters | ||
.union(.uppercaseLetters) | ||
.union(.decimalDigits) | ||
.union(.init(charactersIn: "-_")) | ||
|
||
/// Returns true if and only if `string` contains only characters which are also in `permittedCharacters` | ||
public static func is_cyamlAlpha(_ string: String) -> Bool { | ||
Anchor.permittedCharacters.isSuperset(of: .init(charactersIn: string)) | ||
} | ||
|
||
public let rawValue: String | ||
|
||
public init(rawValue: String) { | ||
self.rawValue = rawValue | ||
} | ||
|
||
public init(stringLiteral value: String) { | ||
rawValue = value | ||
} | ||
} | ||
|
||
/// Conformance of Anchor to CustomStringConvertible returns `rawValue` as `description` | ||
extension Anchor: CustomStringConvertible { | ||
public var description: String { rawValue } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.