//
// In order to convert some functionality to Visual C#, the Java Language Conversion Assistant
// creates "support classes" that duplicate the original functionality.
//
// Support classes replicate the functionality of the original code, but in some cases they are
// substantially different architecturally. Although every effort is made to preserve the
// original architecture of the application in the converted project, the user should be aware that
// the primary goal of these support classes is to replicate functionality, and that at times
// the architecture of the resulting solution may differ somewhat.
//
using System;
using System.Collections.Generic;
using System.Text;
namespace FastReport.Barcode.Aztec
{
///
/// Contains conversion support elements such as classes, interfaces and static methods.
///
internal static class SupportClass
{
/*******************************/
///
/// Copies an array of chars obtained from a String into a specified array of chars
///
/// The String to get the chars from
/// Position of the String to start getting the chars
/// Position of the String to end getting the chars
/// Array to return the chars
/// Position of the destination array of chars to start storing the chars
/// An array of chars
public static void GetCharsFromString(System.String sourceString, int sourceStart, int sourceEnd, char[] destinationArray, int destinationStart)
{
int sourceCounter = sourceStart;
int destinationCounter = destinationStart;
while (sourceCounter < sourceEnd)
{
destinationArray[destinationCounter] = (char)sourceString[sourceCounter];
sourceCounter++;
destinationCounter++;
}
}
/*******************************/
///
/// Sets the capacity for the specified List
///
/// The List which capacity will be set
/// The new capacity value
public static void SetCapacity(System.Collections.Generic.IList vector, int newCapacity) where T : new()
{
while (newCapacity > vector.Count)
vector.Add(new T());
while (newCapacity < vector.Count)
vector.RemoveAt(vector.Count - 1);
}
///
/// Converts a string-Collection to an array
///
/// The strings.
///
public static String[] toStringArray(ICollection strings)
{
String[] result = new String[strings.Count];
strings.CopyTo(result, 0);
return result;
}
///
/// Joins all elements to one string.
///
///
/// The separator.
/// The values.
///
public static string Join(string separator, IEnumerable values)
{
StringBuilder builder = new StringBuilder();
separator = separator ?? String.Empty;
if (values != null)
{
foreach (T value in values)
{
builder.Append(value);
builder.Append(separator);
}
if (builder.Length > 0)
builder.Length -= separator.Length;
}
return builder.ToString();
}
///
/// Fills the specified array.
/// (can't use extension method because of .Net 2.0 support)
///
///
/// The array.
/// The value.
public static void Fill(T[] array, T value)
{
for (int i = 0; i < array.Length; i++)
{
array[i] = value;
}
}
///
/// Fills the specified array.
/// (can't use extension method because of .Net 2.0 support)
///
///
/// The array.
/// The start index.
/// The end index.
/// The value.
public static void Fill(T[] array, int startIndex, int endIndex, T value)
{
for (int i = startIndex; i < endIndex; i++)
{
array[i] = value;
}
}
public static string ToBinaryString(int x)
{
char[] bits = new char[32];
int i = 0;
while (x != 0)
{
bits[i++] = (x & 1) == 1 ? '1' : '0';
x >>= 1;
}
Array.Reverse(bits, 0, i);
return new string(bits);
}
public static int bitCount(int n)
{
int ret = 0;
while (n != 0)
{
n &= (n - 1);
ret++;
}
return ret;
}
/////
///// Savely gets the value of a decoding hint
///// if hints is null the default is returned
/////
/////
///// The hints.
///// Type of the hint.
///// The @default.
/////
//public static T GetValue(IDictionary hints, DecodeHintType hintType, T @default)
//{
// // can't use extension method because of .Net 2.0 support
// if (hints == null)
// return @default;
// if (!hints.ContainsKey(hintType))
// return @default;
// return (T)hints[hintType];
//}
}
}