/// /// /// Copyright (C) 2006 Lennart Lopin /// All Rights Reserved. /// /// This program is free software; you can redistribute it and/or /// modify it under the terms of the GNU General Public License as /// published by the Free Software Foundation; either version 2 of the /// License, or (at your option) any later version. /// /// This program is distributed in the hope that it will be useful, but /// WITHOUT ANY WARRANTY; without even the implied warranty of /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU /// General Public License for more details. /// /// You should have received a copy of the GNU General Public License /// along with this program; if not, write to the Free Software /// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA /// 02111-1307, USA. /// /// using System; using System.Globalization; namespace Pali { public class PaliComparer : object, System.Collections.IComparer { /// /// Default constructor - initializes all fields to default values /// public PaliComparer() { } /// /// TODO - add method description /// /// /// Interface method from IComparer /// /// /// TODO - add parameter description /// TODO - add parameter description public virtual int Compare(object s1, object s2) { try { //get rid of special cases if(s1.ToString() == "aā" || s2.ToString() == "aā") Console.WriteLine("here he is"); if((s1 == null) && (s2 == null)) return 0; else if(s1 == null) return -1; else if(s2 == null) return 1; else if(s1 == s2) return 0; if((s1.Equals(string.Empty) && (s2.Equals(string.Empty)))) return 0; else if(s1.Equals(string.Empty)) return -1; else if(s2.Equals(string.Empty)) return -1; char[] w1 = s1.ToString().ToCharArray(); char[] w2 = s2.ToString().ToCharArray(); for(int i = 0; i < w1.Length && i < w2.Length; i++) { if(w1[i] != w2[i]) { return mapNumber(w1[i]) < mapNumber(w2[i]) ? -1 : 1; } else if(i == (w2.Length-1)) { return 1; } else if(i == (w1.Length-1)) return -1; else continue; } } catch(System.Exception ex) { Console.WriteLine("Error: " + ex.Message.ToString()); } return 0; //throw new System.NotImplementedException(); } public int mapNumber(char a) { switch(a) { case('a'): return 1; case('ā'): return 2; case('i'): return 3; case('ī'): return 4; case('u'): return 5; case('ū'): return 6; case('e'): return 7; case('o'): return 8; case('k'): return 9; case('g'): return 10; case('ṅ'): return 11; case('c'): return 12; case('j'): return 13; case('ñ'): return 14; case('ṭ'): return 15; case('ḍ'): return 16; case('ṇ'): return 17; case('t'): return 18; case('d'): return 19; case('n'): return 20; case('p'): return 21; case('b'): return 22; case('m'): return 23; case('y'): return 24; case('r'): return 25; case('l'): return 26; case('v'): return 27; case('s'): return 28; case('h'): return 29; case('ḷ'): return 30; case('ṃ'): return 31; default: return 0; } } } }