Giter Site home page Giter Site logo

difflib's Introduction

Difflib Build Status

Port of Python's difflib library to Rust. It's provide all necessary tools for comparing word sequences.

Installation

Simply add difflib to your dependencies block in Cargo.toml

[dependencies]
difflib = "0.4.0"

Documentation

Documentation is available at https://github.com/DimaKudosh/difflib/wiki

Example

extern crate difflib;

use difflib::differ::Differ;
use difflib::sequencematcher::SequenceMatcher;

fn main() {
    // unified_diff
    let first_text = "one two three four".split(" ").collect::<Vec<&str>>();
    let second_text = "zero one tree four".split(" ").collect::<Vec<&str>>();
    let diff = difflib::unified_diff(
        &first_text,
        &second_text,
        "Original",
        "Current",
        "2005-01-26 23:30:50",
        "2010-04-02 10:20:52",
        3,
    );
    for line in &diff {
        println!("{:?}", line);
    }

    //context_diff
    let diff = difflib::context_diff(
        &first_text,
        &second_text,
        "Original",
        "Current",
        "2005-01-26 23:30:50",
        "2010-04-02 10:20:52",
        3,
    );
    for line in &diff {
        println!("{:?}", line);
    }

    //get_close_matches
    let words = vec!["ape", "apple", "peach", "puppy"];
    let result = difflib::get_close_matches("appel", words, 3, 0.6);
    println!("{:?}", result);

    //Differ examples
    let differ = Differ::new();
    let diff = differ.compare(&first_text, &second_text);
    for line in &diff {
        println!("{:?}", line);
    }

    //SequenceMatcher examples
    let mut matcher = SequenceMatcher::new("one two three four", "zero one tree four");
    let m = matcher.find_longest_match(0, 18, 0, 18);
    println!("{:?}", m);
    let all_matches = matcher.get_matching_blocks();
    println!("{:?}", all_matches);
    let opcode = matcher.get_opcodes();
    println!("{:?}", opcode);
    let grouped_opcodes = matcher.get_grouped_opcodes(2);
    println!("{:?}", grouped_opcodes);
    let ratio = matcher.ratio();
    println!("{:?}", ratio);
    matcher.set_seqs("aaaaa", "aaaab");
    println!("{:?}", matcher.ratio());
}

difflib's People

Contributors

binarycrusader avatar dimakudosh avatar mark-summerfield avatar mitsuhiko avatar nmlgc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

difflib's Issues

vec vs set

In the sequencematcher the second_sequence_popular is a Vec; but in the Python difflib.py b_popular is a set which may explain why this rust difflib's behavior is different from the Python difflib's behavior.

Also, sequencematcher uses HashMap rather than FnvHashMap (and FnvHashSet for second_sequence_popular); these Fnv- versions should be faster.

Use of deprecated function

If the project is still maintained, the deprecated function .trim_right could be replaced by trim_end.

Roadmap discussion

Would you please say what's done and what still needs to be done?

Is GNU Diffutils the model to strive for feature parity? How do they compare?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.