All Projects → JohnSundell → Sweep

JohnSundell / Sweep

Licence: mit
Fast and powerful Swift string scanning made simple

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Sweep

Cuerdas
String manipulation library for Clojure(Script)
Stars: ✭ 272 (-43.92%)
Mutual labels:  strings
Androidlocalizeplugin
🌏 Android localization plugin. support multiple languages, no need to apply for key.
Stars: ✭ 352 (-27.42%)
Mutual labels:  strings
Phoneinfoga
PhoneInfoga is one of the most advanced tools to scan international phone numbers using only free resources. It allows you to first gather standard information such as country, area, carrier and line type on any international phone number. Then search for footprints on search engines to try to find the VoIP provider or identify the owner.
Stars: ✭ 5,927 (+1122.06%)
Mutual labels:  scanning
Data Structures Algorithms
My implementation of 85+ popular data structures and algorithms and interview questions in Python 3 and C++
Stars: ✭ 273 (-43.71%)
Mutual labels:  strings
Natlas
Scaling Network Scanning. Changes prior to 1.0 may cause difficult to avoid backwards incompatibilities. You've been warned.
Stars: ✭ 333 (-31.34%)
Mutual labels:  scanning
Zmap
ZMap is a fast single packet network scanner designed for Internet-wide network surveys.
Stars: ✭ 4,083 (+741.86%)
Mutual labels:  scanning
ShonyDanza
A customizable, easy-to-navigate tool for researching, pen testing, and defending with the power of Shodan.
Stars: ✭ 86 (-82.27%)
Mutual labels:  scanning
Android Scanner Compat Library
A compat library for Bluetooth Low Energy scanning on Android.
Stars: ✭ 462 (-4.74%)
Mutual labels:  scanning
Celerystalk
An asynchronous enumeration & vulnerability scanner. Run all the tools on all the hosts.
Stars: ✭ 333 (-31.34%)
Mutual labels:  scanning
Konan
Konan - Advanced Web Application Dir Scanner
Stars: ✭ 412 (-15.05%)
Mutual labels:  scanning
Osmedeus
Fully automated offensive security framework for reconnaissance and vulnerability scanning
Stars: ✭ 3,391 (+599.18%)
Mutual labels:  scanning
Dt
DNS tool - display information about your domain
Stars: ✭ 313 (-35.46%)
Mutual labels:  scanning
Stringr
A fresh approach to string manipulation in R
Stars: ✭ 397 (-18.14%)
Mutual labels:  strings
String Theory
Identify and reduce memory used by duplicate .NET strings
Stars: ✭ 273 (-43.71%)
Mutual labels:  strings
Stringz
A lightweight and powerful editor for localizing iOS, macOS, tvOS, and watchOS applications.
Stars: ✭ 440 (-9.28%)
Mutual labels:  strings
js-utils
A collection of dependency-free JavaScript utilities 🔧
Stars: ✭ 22 (-95.46%)
Mutual labels:  strings
Rustscan
🤖 The Modern Port Scanner 🤖
Stars: ✭ 5,218 (+975.88%)
Mutual labels:  scanning
Stringsifter
A machine learning tool that ranks strings based on their relevance for malware analysis.
Stars: ✭ 469 (-3.3%)
Mutual labels:  strings
Philology
An easy way to dynamically replace Strings of your Android App or provide new languages Over-the-air without needed to publish a new release on Google Play.
Stars: ✭ 458 (-5.57%)
Mutual labels:  strings
Cracking The Coding Interview
📚 C++ and Python solutions with automated tests for Cracking the Coding Interview 6th Edition.
Stars: ✭ 396 (-18.35%)
Mutual labels:  strings

Sweep

Swift Package Manager Mac + Linux Twitter: @johnsundell

Welcome to Sweep — a powerful and fast, yet easy to use, Swift string scanning library. Scan any string for substrings appearing between two sets of characters — for example to parse out identifiers or metadata from a string of user-defined text.

Sweep can be dropped into a project as a general-purpose string scanning algorithm, or act as the base for custom, more high-level scanning implementations. It aims to complement the Swift standard library’s built-in string handling APIs, both in terms of its design, and also how its implemented in an efficient way in line with Swift’s various string conventions.

Examples

The easiest way to start using Sweep is to call the substrings method that it adds on top of StringProtocol — meaning that you can use it on both “normal” strings and Substring values.

Here’s an example in which we scan a string for HTML tags, and both identify the names of all tags that appear in the string, and also any text that should be rendered in bold:

import Sweep

let html = "<p>Hello, <b>this is bold</b>, right?</p>"
let tags = html.substrings(between: "<", and: ">")
print(tags) // ["p", "b", "/b", "/p"]

let boldText = html.substrings(between: "<b>", and: "</b>")
print(boldText) // ["this is bold"]

Sweep can also scan for different patterns, such as a prefix appearing at the start of the scanned string, or its end. Here we’re using those capabilities to identify headings in a string of Markdown-formatted text:

import Sweep

let markdown = """
## Section 1

Text

## Section 2
"""

let headings = markdown.substrings(between: [.prefix("## "), "\n## "],
                                   and: [.end, "\n"])

print(headings) // ["Section 1", "Section 2"]

Since Sweep was designed to fit right in alongside Swift’s built-in string APIs, it lets us compose more powerful string scanning algorithms using both built-in functionality and the APIs that Sweep adds — such as here where we’re parsing out an array of tags from a string written using a custom syntax:

import Sweep

let text = "{{tags: swift, programming, xcode}}"
let tagStrings = text.substrings(between: "{{tags: ", and: "}}")
let tags = tagStrings.flatMap { $0.components(separatedBy: ", ") }
print(tags) // ["swift", "programming", "xcode"]

Sweep was also designed to be highly efficient, and only makes a single pass through each string that it scans — regardless of how many different patterns you wish to scan for. In this example, we’re using two custom matchers to parse two pieces of metadata from a string:

import Sweep

let text = """
url: https://swiftbysundell.com
title: Swift by Sundell
"""

var urls = [URL]()
var titles = [String]()

text.scan(using: [
    Matcher(identifiers: ["url: "], terminators: ["\n", .end]) { match, range in
        let string = String(match)
        let url = URL(string: string)
        url.flatMap { urls.append($0) }
    },
    Matcher(identifiers: ["title: "], terminators: ["\n", .end]) { match, range in
        let string = String(match)
        titles.append(string)
    }
])

print(urls) // [https://swiftbysundell.com]
print(titles) // ["Swift by Sundell"]

Sweep is not only efficient in terms of complexity, it also has a very low memory overhead, thanks to it being built according to Swift’s modern string conventions — making full use of types like Substring and String.Index, and avoiding unnecessary copying and mutations when performing its scanning.

Installation

Sweep is distributed as a Swift package, and it’s recommended to install it using the Swift Package Manager, by declaring it as a dependency in your project’s Package.swift file:

.package(url: "https://github.com/JohnSundell/Sweep", from: "0.1.0")

For more information, please see the Swift Package Manager documentation.

Contributions & support

Sweep is developed completely in the open, and your contributions are more than welcome.

Before you start using Sweep in any of your projects, it’s highly recommended that you spend a few minutes familiarizing yourself with its documentation and internal implementation (it all fits in a single file!), so that you’ll be ready to tackle any issues or edge cases that you might encounter.

To learn more about the principles used to implement Sweep, check out “String parsing in Swift” on Swift by Sundell.

Sweep does not come with GitHub Issues-based support, and users are instead encouraged to become active participants in its continued development — by fixing any bugs that they encounter, or improving the documentation wherever it’s found to be lacking.

If you wish to make a change, open a Pull Request — even if it just contains a draft of the changes you’re planning, or a test that reproduces an issue — and we can discuss it further from there.

Hope you enjoy using Sweep! 😀

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].