Git Product home page Git Product logo

diacritics.net's Introduction

Diacritics.NET

Diacritics.NET

Diacritics are used across many languages in order to change the sound-values of the letters to which they are added. In software development, diacritics often have to be replaced with non-diacritics, e.g. to improve usability of user input. Diacritics.NET is a basic mapper between diacritic characters an non-diacritic characters.

Download and Install Diacritics

This library is available on NuGet: https://www.nuget.org/packages/Diacritics/ Use the following command to install Diacritics using NuGet package manager console:

PM> Install-Package Diacritics

You can use this library in any .Net project which is compatible to PCL (e.g. Xamarin Android, iOS, Windows Phone, Windows Store, Universal Apps, etc.)

API Usage

Detect and remove diacritic characters

The most common use case of this library is to detect and remove diacritic characters from a given string.

HasDiacritics simply tells you if the given string contains any diacritic character. The effort for this check is the same as if you remove the characters using RemoveDiacritics.

// Arrange
const string InputString = "Je veux aller à Saint-Étienne";

// Act
bool hasDiacritics = InputString.HasDiacritics();

// Assert
hasDiacritics.Should().BeTrue();

RemoveDiacritics returns a string for which all diacritics have been replaced.

// Arrange
const string InputString = "Je veux aller à Saint-Étienne";

// Act
string removeDiacritics = InputString.RemoveDiacritics();

// Assert
removeDiacritics.Should().Be("Je veux aller a Saint-Etienne");

Using Diacritics with IoC

The example shown above uses extension methods which use a default implementation of IDiacriticsMapper, namely type DefaultDiacriticsMapper. If you're using an IoC container, you can register IDiacriticsMapper either with the provided DefaultDiacriticsMapper or with your own implementation of IDiacriticsMapper.

Add custom diactrics mappings

Diacritics is extensible! You can write your own language accent by implementing IAccentMapping (or AccentMapping base class). DiacriticsMapper accepts any IAccentMapping type at construction time. You are highly welcome to contribute to this library. Just create a fork, commit your changes and create a pull request.

TODO: Add/Remove methods for adding/removing accents at runtime.

License

This project is Copyright © 2015 Thomas Galliker. Free for non-commercial use. For commercial use please contact the author.

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.