X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2FMicrosoft.Build.Tasks%2FMicrosoft.Build.Tasks%2FAssignCulture.cs;h=7e0161c0a3f420820903e015ddb1cd5055e26e7d;hb=10f86fb5fe2212bb57090376ec04847aeb558b4e;hp=560cb0ffc1ceaac72da537e6391dc606e311d22c;hpb=f1f8b8a867c800b21b6a03767252403c2f72cae2;p=mono.git diff --git a/mcs/class/Microsoft.Build.Tasks/Microsoft.Build.Tasks/AssignCulture.cs b/mcs/class/Microsoft.Build.Tasks/Microsoft.Build.Tasks/AssignCulture.cs index 560cb0ffc1c..7e0161c0a3f 100644 --- a/mcs/class/Microsoft.Build.Tasks/Microsoft.Build.Tasks/AssignCulture.cs +++ b/mcs/class/Microsoft.Build.Tasks/Microsoft.Build.Tasks/AssignCulture.cs @@ -3,8 +3,10 @@ // // Author: // Marek Sieradzki (marek.sieradzki@gmail.com) +// Ankit Jain (jankit@novell.com) // // (C) 2006 Marek Sieradzki +// Copyright 2008 Novell, Inc (http://www.novell.com) // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the @@ -25,11 +27,13 @@ // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -#if NET_2_0 using System; +using System.Collections.Generic; +using System.Globalization; using System.IO; using Microsoft.Build.Framework; +using Microsoft.Build.Utilities; namespace Microsoft.Build.Tasks { public class AssignCulture : TaskExtension { @@ -44,33 +48,131 @@ namespace Microsoft.Build.Tasks { { } - [MonoTODO] public override bool Execute () { - return false; + if (files.Length == 0) + return true; + + List all_files = new List (); + List with_culture = new List (); + List no_culture = new List (); + List culture_neutral = new List (); + + foreach (ITaskItem item in files) { + string only_filename, culture, extn; + + if (TrySplitResourceName (item.ItemSpec, out only_filename, out culture, out extn)) { + //valid culture found + ITaskItem new_item = new TaskItem (item); + new_item.SetMetadata ("Culture", culture); + all_files.Add (new_item); + + new_item = new TaskItem (item); + new_item.SetMetadata ("Culture", culture); + with_culture.Add (new_item); + + new_item = new TaskItem (item); + new_item.SetMetadata ("Culture", culture); + new_item.ItemSpec = only_filename + "." + extn; + culture_neutral.Add (new_item); + } else { + //No valid culture + + all_files.Add (item); + no_culture.Add (item); + culture_neutral.Add (item); + } + } + + assignedFiles = all_files.ToArray (); + assignedFilesWithCulture = with_culture.ToArray (); + assignedFilesWithNoCulture = no_culture.ToArray (); + cultureNeutralAssignedFiles = culture_neutral.ToArray (); + + return true; } + [Output] public ITaskItem[] AssignedFiles { get { return assignedFiles; } } + [Output] public ITaskItem[] AssignedFilesWithCulture { get { return assignedFilesWithCulture; } } + [Output] public ITaskItem[] AssignedFilesWithNoCulture { get { return assignedFilesWithNoCulture; } } + [Output] public ITaskItem[] CultureNeutralAssignedFiles { get { return cultureNeutralAssignedFiles; } } + [Required] public ITaskItem[] Files { get { return files; } set { files = value; } } + + //Given a filename like foo.it.resx, splits it into - foo, it, resx + //Returns true only if a valid culture is found + //Note: hand-written as this can get called lotsa times + internal static bool TrySplitResourceName (string fname, out string only_filename, out string culture, out string extn) + { + only_filename = culture = extn = null; + + int last_dot = -1; + int culture_dot = -1; + int i = fname.Length - 1; + while (i >= 0) { + if (fname [i] == '.') { + last_dot = i; + break; + } + i --; + } + if (i < 0) + return false; + + i--; + while (i >= 0) { + if (fname [i] == '.') { + culture_dot = i; + break; + } + i --; + } + if (culture_dot < 0) + return false; + + culture = fname.Substring (culture_dot + 1, last_dot - culture_dot - 1); + if (!CultureNamesTable.ContainsKey (culture)) { + culture = null; + return false; + } + + only_filename = fname.Substring (0, culture_dot); + extn = fname.Substring (last_dot + 1); + return true; + } + + static Dictionary cultureNamesTable; + static Dictionary CultureNamesTable { + get { + if (cultureNamesTable == null) { + cultureNamesTable = new Dictionary (); + foreach (CultureInfo ci in CultureInfo.GetCultures (CultureTypes.AllCultures)) + cultureNamesTable [ci.Name] = ci.Name; + } + + return cultureNamesTable; + } + } + } } -#endif \ No newline at end of file