# HG changeset patch # User Jordan Miner # Date 1337134488 18000 # Node ID 604d20cac836373db24b5a80140db5e6c6531f92 # Parent 1690ebff00a085448259daaae0dbdd9552a755ea Add dynamin.core.array and put contains() there. diff -r 1690ebff00a0 -r 604d20cac836 dynamin/all_core.d --- a/dynamin/all_core.d Tue May 15 20:54:39 2012 -0500 +++ b/dynamin/all_core.d Tue May 15 21:14:48 2012 -0500 @@ -15,7 +15,7 @@ * The Original Code is the Dynamin library. * * The Initial Developer of the Original Code is Jordan Miner. - * Portions created by the Initial Developer are Copyright (C) 2006-2009 + * Portions created by the Initial Developer are Copyright (C) 2006-2012 * the Initial Developer. All Rights Reserved. * * Contributor(s): @@ -25,6 +25,7 @@ module dynamin.all_core; +public import dynamin.core.array; public import dynamin.core.benchmark; public import dynamin.core.console; public import dynamin.core.environment; diff -r 1690ebff00a0 -r 604d20cac836 dynamin/core/array.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dynamin/core/array.d Tue May 15 21:14:48 2012 -0500 @@ -0,0 +1,55 @@ +// Written in the D programming language +// www.digitalmars.com/d/ + +/* + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is the Dynamin library. + * + * The Initial Developer of the Original Code is Jordan Miner. + * Portions created by the Initial Developer are Copyright (C) 2006-2012 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Jordan Miner + * + */ + +module dynamin.core.array; + +/** + * Tests whether or not the specified item is in the specified array. + * Returns: true if the specified item is in the array and false otherwise + * Examples: + * ----- + * "Hello".contains('e') == true + * "Hello".contains('a') == false + * "".contains('e') == false + * assert([2, 3, 7].contains(3) == true); + * assert([2, 3, 7].contains(0) == false); + * ----- + */ +bool contains(T, U)(T[] arr, U item) { + foreach(U item2; arr) { + if(item == item2) + return true; + } + return false; +} + +unittest { + assert("Hello".contains('e') == true); + assert("Hello".contains('a') == false); + assert("".contains('e') == false); + assert([2, 3, 7].contains(3) == true); + assert([2, 3, 7].contains(0) == false); +} + diff -r 1690ebff00a0 -r 604d20cac836 dynamin/core/string.d --- a/dynamin/core/string.d Tue May 15 20:54:39 2012 -0500 +++ b/dynamin/core/string.d Tue May 15 21:14:48 2012 -0500 @@ -30,11 +30,12 @@ */ module dynamin.core.string; +public import dynamin.core.array; + import tango.core.Exception; import tango.text.convert.Utf; import tango.text.convert.Layout; import tango.text.Unicode; -import tango.text.Util; import dynamin.core.global; import dynamin.core.math; @@ -162,36 +163,7 @@ return i; return -1; } -/** - * Tests whether or not the specified char is in the specified string. - * Returns: true if the specified char is in the string and false otherwise - * Examples: - * ----- - * "Hello".contains('e') == true - * "Hello".contains('a') == false - * "".contains('e') == false - * ----- - */ -bool contains(string str, char c) { - foreach(char c2; str) { - if(c == c2) - return true; - } - return false; -} -/// ditto -bool contains(string str, dchar c) { - foreach(dchar c2; str) { - if(c == c2) - return true; - } - return false; -} -unittest { - assert("Hello".contains('e') == true); - assert("Hello".contains('a') == false); - assert("".contains('e') == false); -} + string remove(string str, int start, int count = 1) { return str[0..start] ~ str[start+count..str.length]; } diff -r 1690ebff00a0 -r 604d20cac836 dynamin/painting/text_layout.d --- a/dynamin/painting/text_layout.d Tue May 15 20:54:39 2012 -0500 +++ b/dynamin/painting/text_layout.d Tue May 15 21:14:48 2012 -0500 @@ -418,7 +418,7 @@ /// int opApply(int delegate(ref uint start, ref uint length, ref Format format) dg) { bool inFilter(FormatType type) { - return filter.length == 0 || filter.containsT(type); + return filter.length == 0 || filter.contains(type); } with(owner) { int result; diff -r 1690ebff00a0 -r 604d20cac836 dynamin/painting/windows_text_layout.d --- a/dynamin/painting/windows_text_layout.d Tue May 15 20:54:39 2012 -0500 +++ b/dynamin/painting/windows_text_layout.d Tue May 15 21:14:48 2012 -0500 @@ -36,14 +36,6 @@ //version = TextLayoutDebug; -// TODO: move to array.d -bool containsT(T)(T[] array, T item) { - foreach(T item2; array) { - if(item == item2) - return true; - } - return false; -} template TextLayoutBackend() { uint charToWcharIndex(uint index) { uint wcharIndex = 0;