<commit_before># SwissArmyKnife

SwissArmyKnife is my little utility library. Its target framework is 4.0, the only dependency is System (mscorlib), it doesn't cause warnings and it's fully CLS compliant.

## Current status

I'm in the process of making things available under the right license and moving them over to this project.

Done: 
* Extension methods
 * `object.IsAnyOf()`
 * `IComparable.IsBetween()`
 * `StringBuilder.AppendFormatLine()`
 * `string.FormatWith()`
 * `string.Truncate()`
* Data structures
 * `Stack`

Todo:
* Collections & data structures
 * `FixedList<T>`, a fixed capacity list
 * `BinaryTree`
* IO namespace
* Custom types
* Loads more

## Examples

### Extension methods

#### object.IsAnyOf()

```csharp
int value = 0;

/// Replaces this:
/// if (value == 0 || value == 1 || value == 2)
/// {
///     // Do something
/// }
if (value.IsAnyOf(0, 1, 2))
{
    // Do something
}
```

```csharp
string value = "b";
if (value.IsAnyOf("a", "b", "c"))
{
    // Do something
}
```

#### IComparable.IsBetween()
```csharp
int value = 1;

/// Replaces this:
/// if (value > 0 &amp;&amp;  value < 2)
/// {
///     // Do something
/// }
if (value.IsBetween(0, 2))
{
    // Do something
}
```

```csharp
DateTime lower = new DateTime(2015, 01, 01, 0, 0, 1);
DateTime upper = new DateTime(2015, 12, 31, 23, 59, 59);

DateTime upper = new DateTime(2015, 6, 1, 12, 0, 0);

if (value.IsBetween(lower, upper))
{
    // Do something
}
```

#### StringBuilder.AppendFormatLine()
```csharp

StringBuilder sb = new StringBuilder();

sb.AppendFormatLine("{0}: {1}", "test", 1);
```

#### string.FormatWith()

```csharp
string formattedString = "Employee: {0} (status: {1})".FormatWith("<NAME>", "Fired");
```

```csharp
var employeeName = "{0} {1}";
string formattedString = employeeName.FormatWith("Donald", "Duck");
```

#### string.Truncate()

```csharp
var text = "Lorem ipsum".Truncate(5); // "Lorem"
```

```csharp
var text = "Lorem ipsum";
var truncatedText = text.Truncate(5); // "Lorem"
```

```csharp
var truncatedTextWithSuffix = "Lorem ipsum".Truncate(5, "..."); // "Lorem..."
```

### Data structures

#### Stack

A generic last in, first out stack.

```csharp
var s = new Stack();
s.Push("first");
s.Push("second");

var popFirst = s.Pop(); // "second"
var popSecond = s.Pop(); // "first"
```

## Project structures

### src\SwissArmyKnife

The main project.

### src\SwissArmyKnife.Tests<commit_msg>Fixed typo<commit_after># SwissArmyKnife

SwissArmyKnife is my little utility library. Its target framework is 4.0, the only dependency is System (mscorlib), it doesn't cause warnings and it's fully CLS compliant.

## Current status

I'm in the process of making things available under the right license and moving them over to this project.

Done: 
* Extension methods
 * `object.IsAnyOf()`
 * `IComparable.IsBetween()`
 * `StringBuilder.AppendFormatLine()`
 * `string.FormatWith()`
 * `string.Truncate()`
* Data structures
 * `Stack`

Todo:
* Collections & data structures
 * `FixedList<T>`, a fixed capacity list
 * `BinaryTree`
* IO namespace
* Custom types
* Loads more

## Examples

### Extension methods

#### object.IsAnyOf()

```csharp
int value = 0;

/// Replaces this:
/// if (value == 0 || value == 1 || value == 2)
/// {
///     // Do something
/// }
if (value.IsAnyOf(0, 1, 2))
{
    // Do something
}
```

```csharp
string value = "b";
if (value.IsAnyOf("a", "b", "c"))
{
    // Do something
}
```

#### IComparable.IsBetween()
```csharp
int value = 1;

/// Replaces this:
/// if (value > 0 &amp;&amp;  value < 2)
/// {
///     // Do something
/// }
if (value.IsBetween(0, 2))
{
    // Do something
}
```

```csharp
DateTime lower = new DateTime(2015, 01, 01, 0, 0, 1);
DateTime upper = new DateTime(2015, 12, 31, 23, 59, 59);

DateTime upper = new DateTime(2015, 6, 1, 12, 0, 0);

if (value.IsBetween(lower, upper))
{
    // Do something
}
```

#### StringBuilder.AppendFormatLine()
```csharp

StringBuilder sb = new StringBuilder();

sb.AppendFormatLine("{0}: {1}", "test", 1);
```

#### string.FormatWith()

```csharp
string formattedString = "Employee: {0} (status: {1})".FormatWith("Donald Duck", "Fired");
```

```csharp
var employeeName = "{0} {1}";
string formattedString = employeeName.FormatWith("Donald", "Duck");
```

#### string.Truncate()

```csharp
var text = "Lorem ipsum".Truncate(5); // "Lorem"
```

```csharp
var text = "Lorem ipsum";
var truncatedText = text.Truncate(5); // "Lorem"
```

```csharp
var truncatedTextWithSuffix = "Lorem ipsum".Truncate(5, "..."); // "Lorem..."
```

### Data structures

#### Stack

A generic last in, first out stack.

```csharp
var s = new Stack();
s.Push("first");
s.Push("second");

var popFirst = s.Pop(); // "second"
var popSecond = s.Pop(); // "first"
```

## Project structure

### src\SwissArmyKnife

The main project.

### src\SwissArmyKnife.Tests
{'fraction_non_alphanumeric': 0.1956656346749226, 'fraction_numerical': 0.02435500515995872, 'mean_word_length': 3.8123138033763655, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '277035', 'n_tokens_mistral': 1865, 'n_tokens_neox': 1659, 'n_words': 493}