示例#1
0
        public static unsafe String CallTranslateString(String source, String translationTables, int translationMode)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(source))
                {
                    return(null);
                }
                string inputTables = "";
                if (translationTables.Length > 1)
                {
                    foreach (string s in translationTables.Split(','))
                    {
                        inputTables += @"tables\" + s + ",";
                    }
                    inputTables = inputTables.Substring(0, inputTables.Length - 1);
                }
                else
                {
                    inputTables = @"tables\" + translationTables;
                }
                int inputLength  = source.Length;
                int outputLength = 1;
                while (outputLength < source.Length)
                {
                    outputLength *= 40960;
                }

                char *outBuffer      = (char *)Marshal.AllocHGlobal(outputLength);
                int   r_outputLength = outputLength;
                inputString = source;
                int mode = 8; //default value
                mode = (int)translationMode;
                int code = LouisWrapper.lou_translateString(inputTables, inputString, ref inputLength, outBuffer, ref r_outputLength, null, null, mode);
                if (code == 1)
                {
                    string uniString = Marshal.PtrToStringAuto((IntPtr)outBuffer);
                    Marshal.FreeHGlobal((IntPtr)outBuffer);
                    if (uniString.Length > r_outputLength)
                    {
                        uniString = uniString.Substring(0, r_outputLength);
                    }
                    return(uniString);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception e)
            {
                throw e;
                //return null;
            }
        }
示例#2
0
 public static unsafe bool FreeLibrary()
 {
     try
     {
         LouisWrapper.lou_free();
         return(true);
     }
     catch (Exception e)
     {
         return(false);
     }
 }
示例#3
0
 public static unsafe string GetVersion()
 {
     return("Library version: " + Marshal.PtrToStringAnsi((IntPtr)LouisWrapper.lou_version()));
 }
示例#4
0
 public void Dispose()
 {
     LouisWrapper.FreeLibrary();
     Environment.CurrentDirectory = holder;
     holder = null;
 }
示例#5
0
 public string GetLibraryVersion()
 {
     return(LouisWrapper.GetVersion());
 }
示例#6
0
 public String BackTranslateString(String source, String translationTables, int mode)
 {
     return(LouisWrapper.CallBackTranslateString(source, translationTables, mode));
 }