{"id":644,"date":"2015-08-14T21:44:46","date_gmt":"2015-08-14T21:44:46","guid":{"rendered":"http:\/\/entrian.com\/blog\/?p=644"},"modified":"2021-07-01T07:16:06","modified_gmt":"2021-07-01T07:16:06","slug":"inline-watch-086-object-formatting-power","status":"publish","type":"post","link":"https:\/\/entrian.com\/blog\/inline-watch-086-object-formatting-power\/","title":{"rendered":"Entrian Inline Watch 0.8.6: More object formatting power!"},"content":{"rendered":"<p>I&#8217;ve just published Inline Watch 0.8.6, which includes this new feature:<\/p>\n<ul>\n<li>You can now control the maximum length of the displayed values<\/li>\n<\/ul>\n<p>and a bunch of features related to custom formatting of object instances:<\/p>\n<ul>\n<li>Integer arithmetic in object formats, eg. <code>{right-left}<\/code> to display the width of a rectangle<\/li>\n<li>Pointer arithmetic, eg. <code>{m_str+4}<\/code> where your string actually starts at an offset<\/li>\n<li>Array indexing, eg. <code>{m_arr[N]}<\/code> where you want to display the N&#8217;th member of an array, where <code>N<\/code> can be a literal, <code>{m_arr[4]}<\/code> or another member, <code>{m_arr[m_index]}<\/code><\/li>\n<li>Specifying the length of a string (when your string is long, or not null-terminated), again with a literal, <code>{m_str,8}<\/code>, or another member <code>{m_str,{m_len}} <\/code><\/li>\n<li>Displaying braces now requires them to be backslash escaped &#8211; see the next example:<\/li>\n<li>Force hex or decimal display in object formats, so if you always want your <code>Point<\/code> instances to be displayed in decimal like this: <span style=\"border: 1px solid #e0c000; background-color: #ffffb8; border-radius: 0.6em; padding-right: 0.6em; padding-left: 0.6em; font-family: Calibri, Helvetica Neue, Arial, Helvetica, sans-serif; font-size: 90%;\">{50, 100}<\/span> even if the Visual Studio debugger is set to hex display, you can say <code>\\{{m_x,d}, {m_y,d}\\}<\/code>.  Use an <code>x<\/code> to get hex display.<\/li>\n<\/ul>\n<p>Here&#8217;s an example that demonstrates some of these features. \u00a0(It&#8217;s based on a customer example &#8211; they have a C++ string class whose string buffer includes a leading reference count, and is not NUL-terminated but instead has a length member.)<\/p>\n<pre><span style=\"font-family: Consolas, monospace;\"><span style=\"font-size: small;\"><span style=\"color: #00007f;\"><strong>struct<\/strong><\/span><span style=\"color: #808080;\"> <\/span><span style=\"color: #000000;\">Formatting<\/span>\n<span style=\"color: #000000;\"><strong>{<\/strong><\/span>\n<span style=\"color: #00007f;\"> <strong> const<\/strong><\/span><span style=\"color: #808080;\"> <\/span><span style=\"color: #00007f;\"><strong>char<\/strong><\/span><span style=\"color: #808080;\"> <\/span><span style=\"color: #000000;\"><strong>*<\/strong><\/span><span style=\"color: #000000;\">s<\/span><span style=\"color: #000000;\"><strong>;<\/strong><\/span><span style=\"color: #808080;\">     <\/span><span style=\"color: #007f00;\">\/\/ 4-byte refcount then an unterminated string.<\/span>\n<span style=\"color: #808080;\"> <\/span><span style=\"color: #00007f;\"><strong> int<\/strong><\/span><span style=\"color: #808080;\"> <\/span><span style=\"color: #000000;\">len<\/span><span style=\"color: #000000;\"><strong>;<\/strong><\/span><span style=\"color: #808080;\">           <\/span><span style=\"color: #007f00;\">\/\/ Number of chars in the string, counting from s+4.<\/span>\n<span style=\"color: #808080;\"> <\/span><span style=\"color: #00007f;\"><strong> const<\/strong><\/span><span style=\"color: #808080;\"> <\/span><span style=\"color: #00007f;\"><strong>char<\/strong><\/span><span style=\"color: #808080;\"> <\/span><span style=\"color: #000000;\"><strong>*<\/strong><\/span><span style=\"color: #000000;\">a<\/span><span style=\"color: #000000;\"><strong>[<\/strong><\/span><span style=\"color: #007f7f;\">3<\/span><span style=\"color: #000000;\"><strong>];<\/strong><\/span><span style=\"color: #808080;\">  <\/span><span style=\"color: #007f00;\">\/\/ An array of three C-style strings.<\/span>\n<span style=\"color: #808080;\"> <\/span><span style=\"color: #00007f;\"><strong> int<\/strong><\/span><span style=\"color: #808080;\"> <\/span><span style=\"color: #000000;\">current<\/span><span style=\"color: #000000;\"><strong>;<\/strong><\/span><span style=\"color: #808080;\">       <\/span><span style=\"color: #007f00;\">\/\/ Which of the three strings is the 'current' one?<\/span>\n<\/span><\/span>\n<span style=\"color: #808080;\"> <\/span><span style=\"font-family: Consolas, monospace;\"><span style=\"font-size: small;\"><span style=\"color: #000000;\"> Formatting<\/span><span style=\"color: #000000;\"><strong>()<\/strong><\/span>\n<span style=\"color: #808080;\"> <\/span><span style=\"color: #000000;\"><strong> {<\/strong><\/span>\n<span style=\"color: #808080;\"> <\/span><span style=\"color: #000000;\"> <strong>  <\/strong>s<\/span><span style=\"color: #808080;\"> <\/span><span style=\"color: #000000;\"><strong>=<\/strong><\/span><span style=\"color: #808080;\"> <\/span><span style=\"color: #7f007f;\">\"\\x1\\x2\\x3\\x4TextGARBAGEGARBAGE...\"<\/span><span style=\"color: #000000;\"><strong>;<\/strong><\/span>\n<span style=\"color: #808080;\"> <\/span><span style=\"color: #000000;\"> <strong>  <\/strong>len<\/span><span style=\"color: #808080;\"> <\/span><span style=\"color: #000000;\"><strong>=<\/strong><\/span><span style=\"color: #808080;\"> <\/span><span style=\"color: #007f7f;\">4<\/span><span style=\"color: #000000;\"><strong>;<\/strong><\/span>\n<span style=\"color: #808080;\"> <\/span><span style=\"color: #000000;\"> <strong>  <\/strong>a<\/span><span style=\"color: #000000;\"><strong>[<\/strong><\/span><span style=\"color: #007f7f;\">0<\/span><span style=\"color: #000000;\"><strong>]<\/strong><\/span><span style=\"color: #808080;\"> <\/span><span style=\"color: #000000;\"><strong>=<\/strong><\/span><span style=\"color: #808080;\"> <\/span><span style=\"color: #7f007f;\">\"Zero\"<\/span><span style=\"color: #000000;\"><strong>;<\/strong><\/span>\n<span style=\"color: #808080;\"> <\/span><span style=\"color: #000000;\"> <strong>  <\/strong>a<\/span><span style=\"color: #000000;\"><strong>[<\/strong><\/span><span style=\"color: #007f7f;\">1<\/span><span style=\"color: #000000;\"><strong>]<\/strong><\/span><span style=\"color: #808080;\"> <\/span><span style=\"color: #000000;\"><strong>=<\/strong><\/span><span style=\"color: #808080;\"> <\/span><span style=\"color: #7f007f;\">\"One\"<\/span><span style=\"color: #000000;\"><strong>;<\/strong><\/span>\n<span style=\"color: #808080;\"> <\/span><span style=\"color: #000000;\"> <strong>  <\/strong>a<\/span><span style=\"color: #000000;\"><strong>[<\/strong><\/span><span style=\"color: #007f7f;\">2<\/span><span style=\"color: #000000;\"><strong>]<\/strong><\/span><span style=\"color: #808080;\"> <\/span><span style=\"color: #000000;\"><strong>=<\/strong><\/span><span style=\"color: #808080;\"> <\/span><span style=\"color: #7f007f;\">\"Two\"<\/span><span style=\"color: #000000;\"><strong>;<\/strong><\/span>\n<span style=\"color: #808080;\"> <\/span><span style=\"color: #000000;\"> <strong>  <\/strong>current<\/span><span style=\"color: #808080;\"> <\/span><span style=\"color: #000000;\"><strong>=<\/strong><\/span><span style=\"color: #808080;\"> <\/span><span style=\"color: #007f7f;\">1<\/span><span style=\"color: #000000;\"><strong>;<\/strong><\/span><span style=\"color: #808080;\"> <\/span><span style=\"color: #007f00;\">\/\/ \"One\" is the string to display.<\/span>\n<span style=\"color: #808080;\"> <\/span><span style=\"color: #000000;\"><strong> }<\/strong><\/span>\n<span style=\"color: #000000;\"><strong>};<\/strong><\/span><\/span><\/span><\/pre>\n<p lang=\"en\">With an object formatting rule like this:<\/p>\n<blockquote><p><code>\\{{s + 4,{len}}, {a[current]}\\}<\/code><\/p><\/blockquote>\n<p>a <code>Formatting<\/code> instance displays like this: <span style=\"border: 1px solid #e0c000; background-color: #ffffb8; border-radius: 0.6em; padding-right: 0.6em; padding-left: 0.6em; font-family: Calibri, Helvetica Neue, Arial, Helvetica, sans-serif; font-size: 90%;\">{&#8220;Text&#8221;, &#8220;One&#8221;}<\/span><\/p>\n<p>You can download the new release from <a href=\"http:\/\/entrian.com\/inline-watch\/download.html\">the download page<\/a> or <a href=\"https:\/\/visualstudiogallery.msdn.microsoft.com\/d3fb51d6-d8f3-4872-8825-93f657a8ef62\">the gallery<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve just published Inline Watch 0.8.6, which includes this new feature: You can now control the maximum length of the displayed values and a bunch of features related to custom formatting of object instances: Integer arithmetic in object formats, eg. {right-left} to display the width of a rectangle Pointer arithmetic, eg. {m_str+4} where your string [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,5],"tags":[],"class_list":["post-644","post","type-post","status-publish","format-standard","hentry","category-30days","category-inline-watch-changelog"],"_links":{"self":[{"href":"https:\/\/entrian.com\/blog\/wp-json\/wp\/v2\/posts\/644","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/entrian.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/entrian.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/entrian.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/entrian.com\/blog\/wp-json\/wp\/v2\/comments?post=644"}],"version-history":[{"count":1,"href":"https:\/\/entrian.com\/blog\/wp-json\/wp\/v2\/posts\/644\/revisions"}],"predecessor-version":[{"id":1273,"href":"https:\/\/entrian.com\/blog\/wp-json\/wp\/v2\/posts\/644\/revisions\/1273"}],"wp:attachment":[{"href":"https:\/\/entrian.com\/blog\/wp-json\/wp\/v2\/media?parent=644"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/entrian.com\/blog\/wp-json\/wp\/v2\/categories?post=644"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/entrian.com\/blog\/wp-json\/wp\/v2\/tags?post=644"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}