Title: Replace from an array of strings · Issue #2 · magiclen/node-stringbuilder · GitHub
Open Graph Title: Replace from an array of strings · Issue #2 · magiclen/node-stringbuilder
X Title: Replace from an array of strings · Issue #2 · magiclen/node-stringbuilder
Description: It would be useful if the ReplaceAll method could accept an array. As an example, I altered the ReplaceAll code to produce this: // from javascript call as: sb.replaceFromArray() napi_value ReplaceFromArray(napi_env env, napi_callback_in...
Open Graph Description: It would be useful if the ReplaceAll method could accept an array. As an example, I altered the ReplaceAll code to produce this: // from javascript call as: sb.replaceFromArray() napi_value Replace...
X Description: It would be useful if the ReplaceAll method could accept an array. As an example, I altered the ReplaceAll code to produce this: // from javascript call as: sb.replaceFromArray() napi_value Replace...
Opengraph URL: https://github.com/magiclen/node-stringbuilder/issues/2
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Replace from an array of strings","articleBody":"It would be useful if the ReplaceAll method could accept an array.\r\n\r\nAs an example, I altered the ReplaceAll code to produce this:\r\n// from javascript call as: sb.replaceFromArray()\r\n\r\nnapi_value ReplaceFromArray(napi_env env, napi_callback_info info){\r\n size_t argsLength = 1;\r\n napi_value args[2]; // will hold parameters from a 2d array during a for loop\r\n napi_value me;\r\n int n;\r\n\r\n\t\t// test with hard-coded array containing 2 pairs of strings\r\n\t\t// \"john is some writer\" =\u003e \"john is this joke\"\r\n const char* arr[][2] = {{\"some\", \"this\"},\r\n\t\t\t {\"writer\", \"joke\"}};\r\n\r\n \r\n napi_get_cb_info(env, info, \u0026argsLength, args, \u0026me, 0); // place input parameters into args[]\r\n /* if (argsLength \u003c 2){ // this bit no longer needed\r\n return me;\r\n */\r\n uint16_t* buffer;\r\n int64_t* metadata;\r\n getBufferAndMetaData(env, me, \u0026buffer, \u0026metadata);\r\n uint16_t* pattern;\r\n int64_t patternLength;\r\n bool patternFreeAble;\r\n for (n = 0; n \u003c 2; n++ ) \r\n\t\t{\r\n\t\t \tnapi_create_string_utf8(env, arr[n][0],\r\n NAPI_AUTO_LENGTH ,\r\n \u0026args[0]);\r\n\r\n\t\t\tnapi_create_string_utf8(env, arr[n][1],\r\n NAPI_AUTO_LENGTH ,\r\n \u0026args[1]);\r\n // ..... the rest of the replaceAll code\r\n }\r\n return me;\r\n}\r\n\r\nI also note that the main section from replaceAll is mostly identical to that inside the ReplacePattern function. There is a potential therefore for refactoring, by which this section could be called from a separate function. \r\n\r\nA more sophisticated implementation of ReplaceFromArray() would pass the array as a parameter, although embedding a hard-coded array has the advantage of \"hiding\" the array contents, while still suiting many possible applications.\r\n\r\n","author":{"url":"https://github.com/xthdraft","@type":"Person","name":"xthdraft"},"datePublished":"2018-11-13T04:52:11.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/2/node-stringbuilder/issues/2"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:a488fb26-b4b3-ca05-e42f-10795894abf0 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C82A:169C19:58CEE8F:788282F:696E2A90 |
| html-safe-nonce | 16b1593d0db4c20adbfbd62b1650b05672ff865232729f6d8adaa3404347e755 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDODJBOjE2OUMxOTo1OENFRThGOjc4ODI4MkY6Njk2RTJBOTAiLCJ2aXNpdG9yX2lkIjoiMTEzMzIwMjMwNjQ5NzM5MTI0OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 631f816d951f654700a0d224c675c08d5a6c4a951a246b69a968e28778fa1a79 |
| hovercard-subject-tag | issue:380059380 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/magiclen/node-stringbuilder/2/issue_layout |
| twitter:image | https://opengraph.githubassets.com/febe991a2c89d8d22a50dd29022cea0796ddf031225870bf0075c3a07cb05dd9/magiclen/node-stringbuilder/issues/2 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/febe991a2c89d8d22a50dd29022cea0796ddf031225870bf0075c3a07cb05dd9/magiclen/node-stringbuilder/issues/2 |
| og:image:alt | It would be useful if the ReplaceAll method could accept an array. As an example, I altered the ReplaceAll code to produce this: // from javascript call as: sb.replaceFromArray() napi_value Replace... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | xthdraft |
| hostname | github.com |
| expected-hostname | github.com |
| None | 878b142339d396b81902fd0c6d3f2f41511e1864f596c5a601660d91d0d60e59 |
| turbo-cache-control | no-preview |
| go-import | github.com/magiclen/node-stringbuilder git https://github.com/magiclen/node-stringbuilder.git |
| octolytics-dimension-user_id | 5851348 |
| octolytics-dimension-user_login | magiclen |
| octolytics-dimension-repository_id | 94566134 |
| octolytics-dimension-repository_nwo | magiclen/node-stringbuilder |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 94566134 |
| octolytics-dimension-repository_network_root_nwo | magiclen/node-stringbuilder |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 20fb42f07915f87665e5bccffc415f231d50cfac |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width