public static MutableString GetMatchSubgroup(StringScanner /*!*/ self, int subgroup) { if (subgroup == 0 && self.LastMatch != null) { return(MutableString.Create(self.LastMatch)); } if (self.LastMatchingGroups == null) { return(null); } if (subgroup < 0) { subgroup = self.LastMatchingGroups.Count - subgroup; } if (subgroup >= self.LastMatchingGroups.Count) { return(null); } return(MutableString.Create(self.LastMatchingGroups[subgroup].ToString())); }
public static RubyArray /*!*/ GetNameInfo(RubyClass /*!*/ self, [DefaultProtocol, NotNull] MutableString /*!*/ address, [Optional] object flags) { IPEndPoint ep = UnpackSockAddr(address); IPHostEntry entry = GetHostEntry(ep.Address, false); ServiceName service = SearchForService(ep.Port); RubyArray result = new RubyArray(2); result.Add(HostNameToMutableString(self.Context, entry.HostName)); if (service != null) { result.Add(MutableString.Create(service.Name)); } else { result.Add(ep.Port); } return(result); }
public void Dir2() { RubyClass dir = Context.GetClass(typeof(RubyDir)); Pal1 pal = (Pal1)Context.Platform; var sjis = RubyEncoding.KCodeSJIS.StrictEncoding.GetBytes("ホ"); // use the string encoding if given RubyDir.MakeDirectory(dir, MutableString.CreateBinary(sjis, RubyEncoding.KCodeSJIS.RealEncoding), null); Assert(pal.Entries["ホ"]); // IO system returns UTF8 encoded strings: var entries = RubyDir.GetEntries(dir, MutableString.CreateEmpty()); Assert(entries.Count == 3); Assert(((MutableString)entries[0]).Equals(MutableString.CreateAscii("."))); Assert(((MutableString)entries[1]).Equals(MutableString.CreateAscii(".."))); Assert(((MutableString)entries[2]).Equals(MutableString.Create("ホ", RubyEncoding.UTF8))); pal.Entries.Clear(); }
public static RubyArray /*!*/ GetNameInfo(ConversionStorage <MutableString> /*!*/ stringCast, ConversionStorage <int> /*!*/ fixnumCast, RubyClass /*!*/ self, [NotNull] RubyArray /*!*/ hostInfo, [Optional] object flags) { if (hostInfo.Count < 3 || hostInfo.Count > 4) { throw RubyExceptions.CreateArgumentError("First parameter must be a 3 or 4 element array"); } RubyContext context = self.Context; // We only support AF_INET (IP V4) family AddressFamily addressFamily = ConvertToAddressFamily(stringCast, fixnumCast, hostInfo[0]); if (addressFamily != AddressFamily.InterNetwork) { throw new SocketException((int)SocketError.AddressFamilyNotSupported); } // Lookup the service name for the given port. int port = ConvertToPortNum(stringCast, fixnumCast, hostInfo[1]); ServiceName service = SearchForService(port); // hostInfo[2] should have a host name // if it exists and is not null hostInfo[3] should have an IP address // in that case we use that rather than the host name. object hostName = (hostInfo.Count > 3 && hostInfo[3] != null) ? hostInfo[3] : hostInfo[2]; IPHostEntry entry = GetHostEntry(ConvertToHostString(stringCast, hostName), false); RubyArray result = new RubyArray(2); result.Add(HostNameToMutableString(context, entry.HostName)); if (service != null) { result.Add(MutableString.Create(service.Name)); } else { result.Add(port); } return(result); }
private void AddAbsoluteLibraryPaths(RubyArray /*!*/ result, string applicationBaseDir, ICollection <string> /*!*/ paths) { foreach (var path in paths) { string fullPath; if (applicationBaseDir != null) { try { fullPath = Platform.IsAbsolutePath(path) ? path : Platform.GetFullPath(Path.Combine(applicationBaseDir, path)); } catch (Exception) { // error will be reported on first require: fullPath = path; } } else { fullPath = path; } result.Add(MutableString.Create(fullPath.Replace('\\', '/'))); } }
public static Node /*!*/ ToYaml(double self, [NotNull] RubyRepresenter /*!*/ rep) { MutableString str = RubySites.ToS(rep.Context, self); if (str != null) { if (str.Equals("Infinity")) { str = MutableString.Create(".Inf"); } else if (str.Equals("-Infinity")) { str = MutableString.Create("-.Inf"); } else if (str.Equals("NaN")) { str = MutableString.Create(".NaN"); } } return(rep.Scalar(self, str)); }
public static MutableString /*!*/ ToString(BigDecimal /*!*/ self, [DefaultProtocol][NotNull] MutableString /*!*/ format) { string posSign = ""; int separateAt = 0; Match m = Regex.Match(format.ConvertToString(), @"^(?<posSign>[+ ])?(?<separateAt>\d+)?(?<floatFormat>[fF])?", RegexOptions.ExplicitCapture); Group posSignGroup = m.Groups["posSign"]; Group separateAtGroup = m.Groups["separateAt"]; Group floatFormatGroup = m.Groups["floatFormat"]; if (posSignGroup.Success) { posSign = m.Groups["posSign"].Value; } if (separateAtGroup.Success) { separateAt = Int32.Parse(m.Groups["separateAt"].Value); } bool floatFormat = floatFormatGroup.Success; return(MutableString.Create(self.ToString(separateAt, posSign, floatFormat))); }
public static Node ToYamlNode(MutableString /*!*/ self, [NotNull] RubyRepresenter /*!*/ rep) { if (RubyOps.IsTrue(_IsBinaryData.Target(_IsBinaryData, rep.Context, self))) { return(rep.BaseCreateNode(self.ConvertToBytes())); } string str = self.ConvertToString(); RubyArray props = RubyRepresenter.ToYamlProperties(rep.Context, self); if (props.Count == 0) { MutableString taguri = RubyRepresenter.TagUri(rep.Context, self); char style = (char)0; if (str.StartsWith(":")) { style = '"'; } else { MutableString styleStr = RubyRepresenter.ToYamlStyle(rep.Context, self) as MutableString; if (styleStr != null && styleStr.Length > 0) { style = styleStr.GetChar(0); } } return(rep.Scalar(taguri != null ? taguri.ConvertToString() : "", str, style)); } Hash map = new Hash(rep.Context); map.Add(MutableString.Create("str"), str); RubyRepresenter.AddYamlProperties(rep.Context, self, map, props); return(rep.Map(self, map)); }
private void Inspect2() { const char sq = '\''; var sjisEncoding = RubyEncoding.SJIS; // あ var sjisWide = new byte[] { 0x82, 0xa0 }; // \u{12345} in UTF-8: var utf8 = new byte[] { 0xF0, 0x92, 0x8D, 0x85 }; // \u{12345} in UTF-16: U+d808 U+df45 var utf16 = Encoding.UTF8.GetString(utf8); string s; s = MutableStringOps.GetQuotedStringRepresentation(MutableString.CreateBinary(utf8, RubyEncoding.Binary), false, sq).ToString(); Assert(s == @"'\xF0\x92\x8D\x85'"); s = MutableStringOps.GetQuotedStringRepresentation(MutableString.CreateBinary(utf8, RubyEncoding.Binary), true, sq).ToString(); Assert(s == @"'\xF0\x92\x8D\x85'"); s = MutableStringOps.GetQuotedStringRepresentation(MutableString.CreateBinary(utf8, RubyEncoding.UTF8), false, sq).ToString(); Assert(s == @"'\u{12345}'"); s = MutableStringOps.GetQuotedStringRepresentation(MutableString.CreateBinary(utf8, RubyEncoding.UTF8), true, sq).ToString(); Assert(s == @"'\u{12345}'"); // incomplete character: s = MutableStringOps.GetQuotedStringRepresentation(MutableString.Create("\ud808\udf45\ud808", RubyEncoding.UTF8), false, sq).ToString(); Assert(s == @"'\u{12345}\u{d808}'"); s = MutableStringOps.GetQuotedStringRepresentation(MutableString.CreateBinary(sjisWide, sjisEncoding), false, sq).ToString(); Assert(s == @"'\x82\xA0'"); s = MutableStringOps.GetQuotedStringRepresentation(MutableString.CreateBinary(sjisWide, sjisEncoding), true, sq).ToString(); Assert(s == @"'\x82\xA0'"); }
internal static RubyArray /*!*/ CreateHostEntryArray(IPHostEntry hostEntry, bool packIpAddresses) { RubyArray result = new RubyArray(4); // Canonical Hostname result.Add(MutableString.Create(hostEntry.HostName)); // Aliases RubyArray aliases = new RubyArray(hostEntry.Aliases.Length); foreach (string alias in hostEntry.Aliases) { aliases.Add(MutableString.Create(alias)); } result.Add(aliases); // Address Type result.Add((int)hostEntry.AddressList[0].AddressFamily); // IP Address foreach (IPAddress address in hostEntry.AddressList) { if (packIpAddresses) { byte[] bytes = address.GetAddressBytes(); MutableString str = MutableString.CreateBinary(); str.Append(bytes, 0, bytes.Length); result.Add(str); } else { result.Add(MutableString.Create(address.ToString())); } } return(result); }
public static MutableString GetHostname(RubyClass /*!*/ self) { return(MutableString.Create(Dns.GetHostName())); }
public static RubyArray Unpack(MutableString str, string formatString) { var format = MutableString.Create(formatString); return(MutableStringOps.Unpack(str, format)); }
public ServiceName(int port, string protocol, string name) { _port = port; _protocol = MutableString.Create(protocol); _name = MutableString.Create(name); }
public AddressFamilyName(string name, AddressFamily family) { _name = MutableString.Create(name); _family = family; }
public static MutableString ConvertString(string csString) { return(MutableString.Create(csString, RubyEncoding.UTF8)); }
internal static MutableString /*!*/ Bytes2Hex(byte[] /*!*/ bytes) { return(MutableString.Create(System.BitConverter.ToString(bytes).Replace("-", "").ToLower())); }
public void loadServerSources(String strData) { MutableString strParam = MutableString.Create(strData); m_engine.Operations.InvokeMember(m_rhoframework, "load_server_sources", strParam); }
public static MutableString SetString(RubyContext /*!*/ context, StringScanner /*!*/ self, [NotNull] MutableString /*!*/ str) { self.ScanString = (MutableString)KernelOps.Freeze(context, MutableString.Create(str)); self.Reset(); return(str); }
public static Exception /*!*/ Create(string /*!*/ message) { return(RubyExceptionData.InitializeException(new SocketException(0), MutableString.Create(message))); }
public static MutableString ToJson(Boolean self) { return(MutableString.Create(self ? JSON_TRUE : JSON_FALSE)); }
private void createTabBarButtons(int barType, Object[] hashArray) { for (int i = 0; hashArray != null && i < hashArray.Length; i++) { if (hashArray[i] != null && hashArray[i] is Hash) { String action = null; String icon = null; String label = null; Brush web_bkg_color = null; bool reload = false; bool use_current_view_for_tab = false; object val = null; Hash values = (Hash)hashArray[i]; if (values.TryGetValue((object)MutableString.Create("action"), out val)) { action = val.ToString(); } if (values.TryGetValue((object)MutableString.Create("icon"), out val)) { icon = val.ToString(); } if (values.TryGetValue((object)MutableString.Create("label"), out val)) { label = val.ToString(); } if (values.TryGetValue((object)MutableString.Create("reload"), out val)) { reload = Convert.ToBoolean(val); } if (values.TryGetValue((object)MutableString.Create("web_bkg_color"), out val)) { web_bkg_color = new SolidColorBrush(getColorFromString(val.ToString())); } if (values.TryGetValue((object)MutableString.Create("use_current_view_for_tab"), out val)) { use_current_view_for_tab = Convert.ToBoolean(val); } //if (label == null && barType == 0) // label = ".";//Text can not be empty. it's WP7's restriction!!! if (icon == null)//icon can not be null or empty. so now i don't know how to create separator { icon = getDefaultImagePath(action); } //if (icon == null || action == null) // continue; //tabItem.Header = "Test";to do TabItem tabItem = new TabItem(); tabItem.Header = new RhoTabHeader(label, icon); //if (i == 0)// && use_current_view_for_tab) tabItem.Content = new RhoView(m_appMainPage, m_layoutRoot, action, reload, web_bkg_color); if (values.TryGetValue((object)MutableString.Create("selected_color"), out val)) { tabItem.Background = new SolidColorBrush(getColorFromString(val.ToString())); } if (values.TryGetValue((object)MutableString.Create("disabled"), out val)) { tabItem.IsEnabled = !Convert.ToBoolean(val); } m_tabControl.Items.Add(tabItem); } } }
public static MutableString ToJson(String self, [Optional] GeneratorState state, [Optional] Int32 depth) { return(Generator.ToJson(MutableString.Create(self, RubyEncoding.Binary))); }
private void AddBacktrace(IEnumerable <StackFrame> stackTrace, int skipFrames, bool skipInterpreterRunMethod) { if (stackTrace != null) { foreach (var frame in InterpretedFrame.GroupStackFrames(stackTrace)) { string methodName, file; int line; if (_interpretedFrames != null && _interpretedFrameIndex < _interpretedFrames.Count && InterpretedFrame.IsInterpretedFrame(frame.GetMethod())) { if (skipInterpreterRunMethod) { skipInterpreterRunMethod = false; continue; } InterpretedFrameInfo info = _interpretedFrames[_interpretedFrameIndex++]; if (info.DebugInfo != null) { file = info.DebugInfo.FileName; line = info.DebugInfo.StartLine; } else { file = null; line = 0; } methodName = info.MethodName; // TODO: We need some more general way to recognize and parse non-Ruby interpreted frames TryParseRubyMethodName(ref methodName, ref file, ref line); if (methodName == InterpretedCallSiteName) { // ignore ruby interpreted call sites continue; } } else if (TryGetStackFrameInfo(frame, out methodName, out file, out line)) { // special case: the frame will be added with the next frame's source info: if (line == NextFrameLine) { _nextFrameMethodName = methodName; continue; } } else { continue; } if (_nextFrameMethodName != null) { if (skipFrames == 0) { _trace.Add(MutableString.Create(FormatFrame(file, line, _nextFrameMethodName), _encoding)); } else { skipFrames--; } _nextFrameMethodName = null; } if (skipFrames == 0) { _trace.Add(MutableString.Create(FormatFrame(file, line, methodName), _encoding)); } else { skipFrames--; } } } }
private bool LoadFromPath(Scope globalScope, object self, string /*!*/ path, RubyEncoding /*!*/ pathEncoding, LoadFlags flags, out object loaded) { Assert.NotNull(pathEncoding, path); string[] sourceFileExtensions; if ((flags & LoadFlags.AnyLanguage) != 0) { sourceFileExtensions = DomainManager.Configuration.GetFileExtensions(); } else { sourceFileExtensions = DomainManager.Configuration.GetFileExtensions(_context); } IList <ResolvedFile> files = FindFile(path, (flags & LoadFlags.AppendExtensions) != 0, sourceFileExtensions); if (files.Count == 0) { // MRI: doesn't throw an exception if the path is in $" (performs resolution first though): if (AlreadyLoaded(path, null, flags, sourceFileExtensions)) { loaded = null; return(false); } throw RubyExceptions.CreateLoadError(String.Format("no such file to load -- {0}", path)); } ResolvedFile file = files.First(); string pathWithExtension = path; if (file.AppendedExtension != null) { pathWithExtension += file.AppendedExtension; } if (AlreadyLoaded(path, files, flags) || _unfinishedFiles.Contains(file.Path)) { if ((flags & LoadFlags.ResolveLoaded) != 0) { if (file.SourceUnit != null) { Scope loadedScope; if (!LoadedScripts.TryGetValue(file.Path, out loadedScope)) { throw RubyExceptions.CreateLoadError(String.Format("no such file to load -- {0}", file.Path)); } loaded = loadedScope; } else { loaded = Platform.LoadAssemblyFromPath(file.Path); } } else { loaded = null; } return(false); } try { // save path as is, no canonicalization nor combination with an extension or directory: _unfinishedFiles.Push(file.Path); if (file.SourceUnit != null) { AddScriptLines(file.SourceUnit); ScriptCode compiledCode; if (file.SourceUnit.LanguageContext == _context) { compiledCode = CompileRubySource(file.SourceUnit, flags); } else { compiledCode = file.SourceUnit.Compile(); } loaded = Execute(globalScope, compiledCode); } else { Debug.Assert(file.Path != null); try { Assembly assembly = Platform.LoadAssemblyFromPath(file.Path); DomainManager.LoadAssembly(assembly); loaded = assembly; } catch (Exception e) { throw RubyExceptions.CreateLoadError(e); } } FileLoaded(MutableString.Create(file.Path, pathEncoding), flags); } finally { _unfinishedFiles.Pop(); } return(true); }
public object createString(String str) { return(MutableString.Create(str)); }
public static Exception /*!*/ Create(RubyClass /*!*/ self, [DefaultParameterValue(null)] object message) { return(RubyExceptionData.InitializeException(new SocketException(0), message ?? MutableString.Create("SocketError"))); }
public static MutableString create_string(String str) { return(MutableString.Create(str)); }
private MutableString RubyString(string str) { return(MutableString.Create(str, RubyEncoding.Default)); }
public static MutableString ToString(StringScanner /*!*/ self) { return(MutableString.Create(self.ToString(), self._scanString.Encoding)); }
public static MutableString ToString(StringScanner /*!*/ self) { return(MutableString.Create(self.ToString())); }