aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/sergi/go-diff/diffmatchpatch/diffmatchpatch.go
blob: d3acc32ce13a0439319b69db12c6f74d9854e4f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright (c) 2012-2016 The go-diff authors. All rights reserved.
// https://github.com/sergi/go-diff
// See the included LICENSE file for license details.
//
// go-diff is a Go implementation of Google's Diff, Match, and Patch library
// Original library is Copyright (c) 2006 Google Inc.
// http://code.google.com/p/google-diff-match-patch/

// Package diffmatchpatch offers robust algorithms to perform the operations required for synchronizing plain text.
package diffmatchpatch

import (
	"time"
)

// DiffMatchPatch holds the configuration for diff-match-patch operations.
type DiffMatchPatch struct {
	// Number of seconds to map a diff before giving up (0 for infinity).
	DiffTimeout time.Duration
	// Cost of an empty edit operation in terms of edit characters.
	DiffEditCost int
	// How far to search for a match (0 = exact location, 1000+ = broad match). A match this many characters away from the expected location will add 1.0 to the score (0.0 is a perfect match).
	MatchDistance int
	// When deleting a large block of text (over ~64 characters), how close do the contents have to be to match the expected contents. (0.0 = perfection, 1.0 = very loose).  Note that MatchThreshold controls how closely the end points of a delete need to match.
	PatchDeleteThreshold float64
	// Chunk size for context length.
	PatchMargin int
	// The number of bits in an int.
	MatchMaxBits int
	// At what point is no match declared (0.0 = perfection, 1.0 = very loose).
	MatchThreshold float64
}

// New creates a new DiffMatchPatch object with default parameters.
func New() *DiffMatchPatch {
	// Defaults.
	return &DiffMatchPatch{
		DiffTimeout:          time.Second,
		DiffEditCost:         4,
		MatchThreshold:       0.5,
		MatchDistance:        1000,
		PatchDeleteThreshold: 0.5,
		PatchMargin:          4,
		MatchMaxBits:         32,
	}
}
cm"> * @author Vaadin Ltd. */ public class TestDateField extends CustomComponent { VerticalLayout main = new VerticalLayout(); AbstractDateField<?, ?> df; public TestDateField() { setCompositionRoot(main); createNewView(); } public void createNewView() { main.removeAllComponents(); main.addComponent(new Label("DateField")); df = new com.vaadin.tests.components.TestDateField(); main.addComponent(df); final ErrorMessage errorMsg = new UserError("User error " + df); df.setCaption("DateField caption " + df); df.setDescription("DateField description " + df); df.setComponentError(errorMsg); // FIXME: bug #1138 this makes datefield to render with unknown // component (UIDL tree debug) df.addStyleName("thisShouldBeHarmless"); // Another test: locale final AbstractDateField<?, ?> df1 = new com.vaadin.tests.components.TestDateField( "US locale"); main.addComponent(df1); df1.setLocale(new Locale("en", "US")); final AbstractDateField<?, ?> df2 = new com.vaadin.tests.components.TestDateField( "DE locale"); main.addComponent(df2); df2.setLocale(new Locale("de", "DE")); final AbstractDateField<?, ?> df3 = new com.vaadin.tests.components.TestDateField( "RU locale"); main.addComponent(df3); df3.setLocale(new Locale("ru", "RU")); final AbstractDateField<?, ?> df4 = new com.vaadin.tests.components.TestDateField( "FI locale"); main.addComponent(df4); df4.setLocale(new Locale("fi", "FI")); } @Override public void attach() { final ClassResource res = new ClassResource("m.gif"); df.setIcon(res); super.attach(); } }